Bug #80411 [Opn->Ver]: References to null-serialized object break serialize()

From: Date: Wed, 25 Nov 2020 16:13:20 +0000
Subject: Bug #80411 [Opn->Ver]: References to null-serialized object break serialize()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230614@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80411&edit=1 ID: 80411 Updated by: nikic@php.net Reported by: whaanstra at eljakim dot nl Summary: References to null-serialized object break serialize() -Status: Open +Status: Verified Type: Bug Package: *General Issues PHP Version: 7.4.12 Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2020-11-24 16:54:37] whaanstra at eljakim dot nl Description: ------------ The reference to the UnSerializable object is serialized as a null, instead of as a reference. In addition, the serializer still sees it as a reference, causing the count of reference-able objects to be off. In my test script, $recovered[3] references $recovered[1] instead of $recovered[2]. This might be related to https://bugs.php.net/bug.php?id=77302, which also involved an empty serialize() method, and was fixed in the same version this was introduced, namely 7.3.4. Version comparison: https://3v4l.org/YD9fS Test script: --------------- class UnSerializable implements Serializable { public function serialize() {} public function unserialize($serialized) {} } $unser = new UnSerializable(); $arr = [$unser]; $arr[] = &$arr[0]; $arr[] = 'endcap'; $arr[] = &$arr[2]; $data = serialize($arr); echo $data . PHP_EOL; $recovered = unserialize($data); var_export($recovered); Expected result: ---------------- a:4:{i:0;N;i:1;R:2;i:2;s:6:"endcap";i:3;R:3;} array ( 0 => NULL, 1 => NULL, 2 => 'endcap', 3 => 'endcap', ) Actual result: -------------- a:4:{i:0;N;i:1;N;i:2;s:6:"endcap";i:3;R:3;} array ( 0 => NULL, 1 => NULL, 2 => 'endcap', 3 => NULL, ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80411&edit=1

« previous php.bugs (#230614) next »