PHP 8.1 : Phasing out Serializable Interface
20, November 2021

PHP 7.4 pointed out some issues with Serializable interface and introduced a new mechanism to customize object serialization.

And PHP 8.1 has started to phase out usage of Serializable interface as much as possible.


PHP 8.1 will trigger deprecation warning if any class implements Serializable interface but do not contain __serialize()/__unserialize() method. Such class will totally stop working from PHP 9.0 as Serializable interface will be removed.


But I want to support both PHP <7.4 and 8.1

To support <7.4 versions, we can implement both Serializable interface and __serialize()/__unserialize(). On <7.4 versions, PHP will keep using the Serializable interface while latest versions will use new __serialize()/__unserialize() methods.\


RFC: https://wiki.php.net/rfc/phase_out_serializable


Write comment about this article: