#50775 [Com]: Array does not serialize properly

From: Date: Sat, 16 Jan 2010 21:56:06 +0000
Subject: #50775 [Com]: Array does not serialize properly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-146741@lists.php.net to get a copy of this message
ID: 50775 Comment by: tolkad dot freenode at gmail dot com Reported By: tolkad dot freenode at gmail dot com Status: Feedback Bug Type: Arrays related Operating System: All PHP Version: 5.2.12 New Comment: I am re-assigning $x to a new recursive array created by unserializing that string. For some reason PHP doesn't treat this like a recursive array when re-serializing it and when var_dumping it. Previous Comments: ------------------------------------------------------------------------ [2010-01-16 03:45:55] rasmus@php.net Can you explain why you think the last var_dump() should show recursion? Looking at it, I don't see it since you are re-assigning $x there and you lose the recursive reference in doing so. ------------------------------------------------------------------------ [2010-01-16 01:27:55] tolkad dot freenode at gmail dot com Description: ------------ When certain strings are unserialized they do not reserialize properly. Reproduce code: --------------- <?php $x = array(); $x[] = &$x; var_dump($x); $z = serialize($x); echo $z . "\n"; var_dump(unserialize($z)); echo "\n\n\n"; $x = unserialize("a:1:{i:0;R:1;}"); var_dump($x); $z = serialize($x); echo $z . "\n\n"; var_dump(unserialize($z)); Expected result: ---------------- array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } a:1:{i:0;a:1:{i:0;R:2;}} array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } a:1:{i:0;R:1;} array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } Actual result: -------------- array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } a:1:{i:0;a:1:{i:0;R:2;}} array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } a:1:{i:0;a:1:{i:0;a:1:{i:0;N;}}} array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50775&edit=1

« previous php.bugs (#146741) next »