From: phplists at stanvassilev dot com Operating system: Any PHP version: 5.4.5 Package: Scripting Engine problem Bug Type: Bug Bug description:Incorrect serialization with circular references
Description: ------------ The documentation says references and circular references should serialize properly. I've found that serialize would first copy the referenced variable, before detecting the reference. This not only doubles the serialized output, but produced incorrect copy when unserialized. Test script: --------------- $original = array('hello'); $original[] = & $original; echo serialize($original); // Output (notice the duplication): // "a:2:{i:0;s:5:"hello";i:1;a:2:{i:0;s:5:"hello";i:1;R:3;}}" $duplicate = unserialize(serialize($x)); // Now I modify both the original and the duplicate in an identical way. // But I get different results, because the duplicate points to a copy of // itself, instead of pointing to itself. $original[0] = 'world'; $duplicate[0] = 'world'; var_dump($original); // Produces (notice it says "world" both times, i.e. it points to itself): // array(2) { [0]=> string(5) "world" [1]=> &array(2) { [0]=> string(5) "world" [1]=> *RECURSION* } } var_dump($duplicate); // Produces (notice the second time it says "hello" i.e. it's a copy): // array(2) { [0]=> string(5) "world" [1]=> &array(2) { [0]=> string(5) "hello" [1]=> *RECURSION* } } Expected result: ---------------- There should be NO copies of "hello" left: array(2) { [0]=> string(5) "world" [1]=> &array(2) { [0]=> string(5) "world" [1]=> *RECURSION* } } There should be NO duplication in the serialized output: "a:2:{i:0;s:5:"hello";i:1;???;}" (Fill-in the "???" appropriately :) ) Actual result: -------------- A copy of "hello" is left: array(2) { [0]=> string(5) "world" [1]=> &array(2) { [0]=> string(5) "hello" [1]=> *RECURSION* } } There is duplication in the serialized output: "a:2:{i:0;s:5:"hello";i:1;a:2:{i:0;s:5:"hello";i:1;R:3;}}" -- Edit bug report at https://bugs.php.net/bug.php?id=62634&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62634&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62634&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62634&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=62634&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62634&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=62634&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=62634&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=62634&r=needscript Try newer version: https://bugs.php.net/fix.php?id=62634&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=62634&r=support Expected behavior: https://bugs.php.net/fix.php?id=62634&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=62634&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=62634&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=62634&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62634&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=62634&r=dst IIS Stability: https://bugs.php.net/fix.php?id=62634&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=62634&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=62634&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=62634&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=62634&r=mysqlcfg