|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-06-16 11:14 UTC] remi@php.net
Description:
------------
On 32bits build, ext/standard/tests/serialize/bug64146.phpt fails.
Test script:
---------------
bug64146.phpt with a dump of the serialized string.
Expected result:
----------------
On 64 bits we have (test OK)
string(108) "O:1:"A":1:{s:1:"a";a:2:{i:0;C:1:"B":24:{O:1:"C":1:{s:1:"c";i:1;}}i:1;C:1:"B":24:{O:1:"C":1:{s:1:"c";i:2;}}}}"
Actual result:
--------------
On 32 bits we have (failed test)
string(87) "O:1:"A":1:{s:1:"a";a:2:{i:0;C:1:"B":24:{O:1:"C":1:{s:1:"c";i:1;}}i:1;C:1:"B":4:{r:4;}}}"
Patchesserialize.patch (last revision 2014-06-17 09:56 UTC by remi@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 19:00:01 2025 UTC |
Apart from the free_list issue, the patch has the additional problems that object R refs will not be created for objects created in serialize(). Consider the following script: <?php class Test implements Serializable { public function serialize() { $obj = new stdClass; return serialize([$obj, $obj]); } public function unserialize($str) { var_dump(unserialize($str)); } } unserialize(serialize(new Test)); Here an array with two identical objects is serialized and as such it also should unserialize to the same object. Current behavior: ~/dev/php-5.6$ sapi/cli/php t18.php array(2) { [0]=> object(stdClass)#2 (0) { } [1]=> object(stdClass)#2 (0) { } } After patch: ~/dev/php-5.6$ sapi/cli/php t18.php array(2) { [0]=> object(stdClass)#2 (0) { } [1]=> object(stdClass)#3 (0) { } } So just excluding objects created during serialize() might solve the test failure, but will introduce problems in other cases. I think the only way to fix this issue is to retain a reference to all objects that are serialized and drop it after serialization is finished. This avoids the possibility that object handles or memory addresses are reused during serialization. This is how this was fixed in PHP 7: https://github.com/php/php-src/commit/8be73f2650582423ec1d3c4b65a77c450f6683a0 https://github.com/php/php-src/commit/75860fa8e1d8ce0c9fd2b505bf7663a4936a7a39 However the same approach is likely not feasible in 5.x due to ABI restrictions.