#27350 [Ver->Bgs]: Incorrect unserialization after __sleep()
| From: | curt@php.net | Date: | Mon, 30 Aug 2004 17:22:05 +0000 |
| Subject: | #27350 [Ver->Bgs]: Incorrect unserialization after __sleep() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-65467@lists.php.net to get a copy of this message | ||
ID: 27350
Updated by: curt@php.net
Reported By: davojan at mail dot ru
-Status: Verified
+Status: Bogus
Bug Type: *General Issues
Operating System: *
PHP Version: 5CVS-2004-03-15
New Comment:
Duplicate of #26737 http://bugs.php.net/26737
Previous Comments:
------------------------------------------------------------------------
[2004-02-22 19:33:01] sniper@php.net
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.
------------------------------------------------------------------------
[2004-02-22 10:57:42] 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] =>
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27350&edit=1