-
Type: New Feature
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
Our PHP 8.1 testing on GitHub Actions revealed a new deprecation in PHP 8.1:
Deprecated: The Serializable interface is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in Unknown on line 0
Depending on the BC impact, we should either silence this warning explicitly or fix the usage.
Related RFCs:
- https://wiki.php.net/rfc/custom_object_serialization
- https://wiki.php.net/rfc/phase_out_serializable
The few implementations of __serialize() in extensions within php-src all return indexed arrays (e.g. ArrayObject). That appears in various userland implementations as well (e.g. Symfony's AbstractToken), but there are other examples of an implementation returning an associative array (e.g. Symfony's Route). The examples in the original RFC actually used associative arrays, so I assume the only requirement is that a class' own __serialize() and __unserialize() methods be consistent with each other.
In PHPC, I would prefer to use associative arrays since we already have helper functions to return such HashTables (currently used by get_debug_info and get_properties handlers). I assume the examples using indexed arrays are doing so for conciseness and to avoid serializing property names in the output; however, that design choice also means the serialization format is a bit more fragile since the order of fields becomes significant.