From: al dot the dot x at gmail dot com Operating system: ANY PHP version: Irrelevant PHP Bug Type: Documentation problem Bug description: Serialize / Unserialize Behavior with Objects including References
Description: ------------ As discussed in several bug reports and in the additional comments in the PHP Documentation site (eventually, with some reading / searching), the functions serialize() and unserialize() do not restore references to other objects in PHP 4. As that this behavior is unexpected _and_ intrinsic to the use of session data in PHP, please consider including a caveat or clarification in the documentation XML for the affected functions, the "Classes and Objects" section, and the "Session-Handling Functions" section. Certainly, there's a workaround with __sleep() and __wakeup(), but this really needs to be addressed in the primary documentation in all these places, since the thread regarding that behavior is now buried among others and only appears on the description of serialize(). I also understand that this has been fixed as of PHP 5, but that's not a very helpful explanation, Most hosting providers currently run PHP 4.3.x or 4.4.x and place low priority on upgrading until the next major Apache version is released (maybe not even then, the slackers). Reproduce code: --------------- // Consider: class dataObject { var $data = NULL; var $pointer = NULL; function dataObject ($newData = false) { if ($newData !== false) $this->data = $newData; } // END constructor function setPointer (&$newPtr) { return ($this->pointer =& $newPtr); } // END setPointer } // END class dataObject $A = new base('This is A'); $B = new base('This is B'); $A->setPointer(&$B); $C = serialize($A); // Now check the original for reference... $B->data = "Still B, but different"; echo $A->pointer->data; // Funky syntax, I know... // Output as expected: "Still B, but different" // But do the same on the serialized version... unset($A); $A = unserialize($C); $B->data = "Where's B now?"; echo $A->pointer->data; // Output is old "This is B"... Not cool. // Reference is not preserved. -- Edit bug report at http://bugs.php.net/?id=35579&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=35579&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=35579&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=35579&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=35579&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35579&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35579&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35579&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35579&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35579&r=support Expected behavior: http://bugs.php.net/fix.php?id=35579&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35579&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35579&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35579&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35579&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35579&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35579&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35579&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35579&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35579&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35579&r=mysqlcfg