From: ehassler at synapsestudios dot com
Operating system: Windows Vista, some Linux 2.6.9
PHP version: 5.2.6
PHP Bug Type: Class/Object related
Bug description: Unserializing with __wakeup that removes child causes
subsequent refs to shift
Description:
------------
During unserialization of a 3 deep non-recursive but not-a-tree data
structure (more like a diamond) where, on nodes in level 2 a __wakeup
causes all references to a child node of a certain class to be removed,
when that child node would occur in subsequent level 2 nodes' child spots,
the reference instead now points to the next level 2 node instead of any
level 3 node. More specifically, it points to the first level 2 node after
the one that removed said child.
The sample code makes it more clear.
Reproduce code:
---------------
class B {
public $value;
function __construct($value){ $this->value = $value; }
function __wakeup()
{
if($this->value instanceof C)
$this->value = C::$instance;
}
}
class C { static public $instance; }
C::$instance = new C;
$A = array( new B(C::$instance), new B(C::$instance), new
B(C::$instance) );
var_dump($A);
$A = unserialize(serialize($A));
var_dump($A);
Expected result:
----------------
array
0 =>
object(B)[2]
public 'value' =>
object(C)[1]
1 =>
object(B)[3]
public 'value' =>
object(C)[1]
2 =>
object(B)[4]
public 'value' =>
object(C)[1]
array
0 =>
object(B)[5]
public 'value' =>
object(C)[1]
1 =>
object(B)[7]
public 'value' =>
object(C)[1]
2 =>
object(B)[8]
public 'value' =>
object(C)[1]
Actual result:
--------------
array
0 =>
object(B)[2]
public 'value' =>
object(C)[1]
1 =>
object(B)[3]
public 'value' =>
object(C)[1]
2 =>
object(B)[4]
public 'value' =>
object(C)[1]
array
0 =>
object(B)[5]
public 'value' =>
object(C)[1]
1 =>
object(B)[6]
public 'value' =>
&object(B)[6]
2 =>
object(B)[7]
public 'value' =>
object(B)[6]
public 'value' =>
&object(B)[6]
--
Edit bug report at http://bugs.php.net/?id=46140&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=46140&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=46140&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=46140&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=46140&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=46140&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=46140&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=46140&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=46140&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=46140&r=support
Expected behavior: http://bugs.php.net/fix.php?id=46140&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=46140&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=46140&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=46140&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46140&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46140&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=46140&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=46140&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=46140&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=46140&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=46140&r=mysqlcfg