Re: serialize bug with array that references to itself?
| From: | Andrey Hristov | Date: | Wed, 03 Nov 2004 13:31:53 +0000 |
| Subject: | Re: serialize bug with array that references to itself? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13706@lists.php.net to get a copy of this message | ||
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