|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-02-22 10:57 UTC] davojan at mail dot ru
Description:
------------
When unserializing after __sleep(), private and protected fields are duplicated with the public ones with the same name.
Note, that in php5.0.0b2 the example works fine. I think it's because of "foreach", which:
- in php5b4: gives the plane names of fields;
- in php5b2: there was a string with additional information about scope ("*", for example) and with '\0' delimiters.
Reproduce code:
---------------
<?
class foo {
public $x = 1;
protected $y = 2;
private $z = 3;
function __sleep()
{
foreach ($this as $Key => $Value) {
$Result[] = $Key;
}
return $Result;
}
}
session_start();
$_SESSION['foo'] = new foo();
print_r ($_SESSION['foo']);
session_write_close();
session_start();
print_r ($_SESSION['foo']);
?>
Expected result:
----------------
foo Object
(
[x] => 1
[y:protected] => 2
[z:private] => 3
)
foo Object
(
[x] => 1
[y:protected] => 2
[z:private] => 3
)
Actual result:
--------------
foo Object
(
[x] => 1
[y:protected] => 2
[z:private] => 3
)
foo Object
(
[x] => 1
[y:protected] => 2
[z:private] => 3
[y] =>
[z] =>
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 12:00:01 2025 UTC |
This is not session related but serialize/unserialize problem. Here's better test script: <?php class foo { public $x = 1; protected $y = 2; private $z = 3; function __sleep () { foreach ($this as $Key => $Value) { $Result[] = $Key; } return $Result; } } $foo = new foo(); $bar = unserialize(serialize($foo)); print_r($foo); print_r($bar); ?> Output is the same as in the initial report.