Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-1849

Handle deprecation of Serializable in PHP 8.1

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 1.11.0-alpha1, 1.11.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      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:

      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.

            jmikola@mongodb.com Jeremy Mikola
            andreas.braun@mongodb.com Andreas Braun
            0 Vote for this issue
            3 Start watching this issue