Re: [RFC] Phasing out Serializable
| From: | Nikita Popov | Date: | Wed, 24 Mar 2021 09:55:14 +0000 |
| Subject: | Re: [RFC] Phasing out Serializable | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-113736@lists.php.net to get a copy of this message | ||
On Wed, Mar 24, 2021 at 10:38 AM Côme Chilliet <
come.chilliet@fusiondirectory.org> wrote:
> Le Tue, 23 Mar 2021 17:01:40 +0100,
> Nicolas Grekas <nicolas.grekas+php@gmail.com> a écrit :
> > Picking up a loose thread:
> > > https://wiki.php.net/rfc/custom_object_serialization
> > > introduced a
> > > replacement for Serializable in PHP 7.4, so it's time to think about
> > > deprecating and removing the old mechanism:
> > >
> > > https://wiki.php.net/rfc/phase_out_serializable
> > >
> > > This RFC follows a rather conversative approach. In PHP 8.1 there will
> be a
> > > deprecation warning if Serializable is implemented without also
> > > implementing __serialize() and __unserialize(). In PHP 9.0, support for
> > > Serializable is dropped internally, and only the interface retained.
> In PHP
> > > 10.0 the interface is dropped as well.
> > >
>
> It is not clear neither in
> https://wiki.php.net/rfc/custom_object_serialization
> nor in the documentation if it is possible to call parent::__serialize()
> to
> only add a few fields to serialization.
>
> Is this legal/correct/useful:
>
> public __serialize ( ) : array
> {
> $data = parent::__serialize();
> $data['specialField'] = $data['special']->complicatedStuff();
> unset($data['special']);
> return $data;
> }
>
> public __unserialize ( array $data ) : void
> {
> $data['special'] = new SpecialComplicatedThing($data['specialField']);
> unset($data['specialField']);
> parent::__unserialize($data);
> }
>
Yes, this is possible.
Regards,
Nikita