|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-02-23 08:44 UTC] nikic@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: nikic
[2021-02-23 08:44 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 11:00:01 2025 UTC |
Description: ------------ If you have a new class extends an ArrayObject, it will display a warning if you implement the __unserialize method with the type hinting of the first parameter: Warning: Declaration of Collection::__unserialize(array $data): void should be compatible with ArrayObject::__unserialize($serialized) Test script: --------------- class Collection extends \ArrayObject { public function __serialize(): array { return $this->getArrayCopy(); } public function __unserialize(array $data): void { $this->__construct($data); } } $collection = new Collection([ 'name' => 'Hello World', 'path' => [ 'of' => [ 'the' => 'Road', 'number' => 20, 'text_a' => ' Bad Boy!', 'text_b' => 'Good Boy! ', ], ], ]); $s1 = serialize($collection); var_dump($s1); $s2 = unserialize($s1); var_dump($s2); Expected result: ---------------- string(195) "O:16:"Razy\CCollection":2:{s:4:"name";s:11:"Hello World";s:4:"path";a:1:{s:2:"of";a:4:{s:3:"the";s:4:"Road";s:6:"number";i:20;s:6:"text_a";s:12:" Bad Boy!";s:6:"text_b";s:12:"Good Boy! ";}}}" object(Razy\CCollection)#66 (1) { ["storage":"ArrayObject":private]=> array(2) { ["name"]=> string(11) "Hello World" ["path"]=> array(1) { ["of"]=> array(4) { ["the"]=> string(4) "Road" ["number"]=> int(20) ["text_a"]=> string(12) " Bad Boy!" ["text_b"]=> string(12) "Good Boy! " } } } } Actual result: -------------- Warning: Declaration of Collection::__unserialize(array $data): void should be compatible with ArrayObject::__unserialize($serialized) in ... string(195) "O:16:"Razy\CCollection":2:{s:4:"name";s:11:"Hello World";s:4:"path";a:1:{s:2:"of";a:4:{s:3:"the";s:4:"Road";s:6:"number";i:20;s:6:"text_a";s:12:" Bad Boy!";s:6:"text_b";s:12:"Good Boy! ";}}}" object(Razy\CCollection)#66 (1) { ["storage":"ArrayObject":private]=> array(2) { ["name"]=> string(11) "Hello World" ["path"]=> array(1) { ["of"]=> array(4) { ["the"]=> string(4) "Road" ["number"]=> int(20) ["text_a"]=> string(12) " Bad Boy!" ["text_b"]=> string(12) "Good Boy! " } } } }