Bug->Doc #79352 [Opn]: ArrayObject::serialize and ArrayObject::unserialize are no longer overrideable
| From: | nikic@php.net | Date: | Sat, 07 Mar 2020 09:48:12 +0000 |
| Subject: | Bug->Doc #79352 [Opn]: ArrayObject::serialize and ArrayObject::unserialize are no longer overrideable | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17379@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79352&edit=1
ID: 79352
Updated by: nikic@php.net
Reported by: tarasov dot igor at gmail dot com
Summary: ArrayObject::serialize and ArrayObject::unserialize
are no longer overrideable
Status: Open
-Type: Bug
+Type: Documentation Problem
Package: SPL related
Operating System: Linux
PHP Version: 7.4.3
Block user comment: N
Private report: N
New Comment:
You need to override __serialize() and __unserialize(). The Serializable implementation only exists
to decode payloads from old PHP versions, and will only be used in that case.
Reclassifying as a documentation problem.
Previous Comments:
------------------------------------------------------------------------
[2020-03-07 09:43:44] tarasov dot igor at gmail dot com
Description:
------------
If you inherit from ArrayObject and then try to override serialize and unserialize methods,
you'll notice that starting with PHP 7.4 these are not executed at all. There are no mentions
in the documentation describing this change. Sure, there are new __serialize and __unserialize, but
this backward-incompatible change and is not described anywhere.
If you create a custom class implementing Serializable interface, you can still override these
methods in child classes, no problem there.
Not sure if this change affects only ArrayObject, I suspect there might be other built-in classes
that were changed the same way.
Test script:
---------------
class Foo extends \ArrayObject {
public function serialize() {
return 'test';
}
}
echo serialize(new Foo);
Expected result:
----------------
C:3:"Foo":4:{test}
Actual result:
--------------
O:3:"Foo":3:{i:0;i:0;i:1;a:0:{}i:2;a:0:{}}
So, Foo::serialize is never executed. And it's not like the results are ignored, you can even
change it's body to die statement and it won't stop there.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79352&edit=1