Re: serialize bug with array that references to itself?

From: Date: Wed, 03 Nov 2004 15:10:04 +0000
Subject: Re: serialize bug with array that references to itself?
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-13709@lists.php.net to get a copy of this message
Feel free to file a bug report at http://bugs.php.net .Mention in the subject there there is core dump. Thanks, Andrey Francisco M. Marzoa Alonso wrote:
Should I fill a bug notification report or so? (where are them? ;-)) Andrey Hristov wrote:
Francisco M. Marzoa Alonso wrote:
Try this code: <pre> <?php $Arr = array(); $Arr['self'] = &$Arr; var_dump ( $Arr ); $serdata = serialize ($Arr); $Arr2 = unserialize ( $serdata ); echo "\n\n"; var_dump ( $Arr2 ); ?> </pre> The second array is expected to be exactly as $Arr, but it doesn't. This is the output for that code: array(1) { ["self"]=> array(1) { ["self"]=> *RECURSION* } } array(1) { ["self"]=> array(1) { ["self"]=> NULL } } As you can see the second array has a NULL value where the first one had a recursive reference. Can this be considered as a bug of PHP serialization system?
Looks as such. While looking at this one, I cooked a little example which cores ZE2 (5.1.0-dev) <?php class a{} class b{} $a=new a; $b=new b; $a->a=$b; $c=array($a,$b); var_dump($c,$d=serialize($c)); var_dump($e=unserialize($d)); $d[0]->a->prop=1; var_dump($d); ?> If one looks at it she will see that I have an error in the example and instead of $d[0]->a I have to use $e[0] , still a Segmentation Fault is not tolerable. This works ok : <?php class a{} class b{} $a=new a; $b=new b; $a->a=$b; $c=array($a,$b); var_dump($c, $d=serialize($c)); var_dump($e=unserialize($d)); $d[0]->a->prop=1; var_dump($d); ?> $e is : array(2) { [0]=> object(a)#3 (1) {
    ["a"]=>
    object(b)#4 (1) {
      ["prop"]=>
      int(1)
    }
} [1]=> object(b)#4 (1) {
    ["prop"]=>
    int(1)
} } Andrey


« previous php.internals (#13709) next »