Skip to content

Clarify what to do with Serializable interface #5616

Description

@LeoZandvliet

Affected page

https://www.php.net/manual/en/class.serializable.php

Current issue

First time in years I had to write a class that would be serialized for caching.
So created a class implementing Serializable, functions serialize and unserialize(string $data) are automatically created, but also deprecated messages about not implementing __serialize and __unserialize(array $data).
Looking up Interface Serializable on what to do and the difference between the methods. The example looks outdated to me, so dig further. Finally found this RFC: Phasing out Serializable.

Suggested improvement

Would it align with the phasing out path to add a second warning/alert on that Interface Serializable page:

Note: if you have to support php < v8.1, implement all of these: __serialize(), serialize(), __unserialize(), unserialize(). If supporting only >= 8.1, implement only the magic functions __serialize() and __unserialize().

And/or add a reference to the RFC Phasing out Serializable

Additional context (optional)

If using ONLY the magic methods,
Is there an alternative for $someObject instanceof Serializable ?
For example: https://onlinephp.io/c/c7ecd

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions