# [RFC] Phasing out Serializable

- Thread: https://externals.io/message/113736
- Original archive: https://news-web.php.net/php.internals/113736
- Started by Nikita Popov on 2021-03-24T09:55:14+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #113724 — Nicolas Grekas — 2021-03-23T16:01:40+00:00

URL: https://externals.io/message/113736#113724

Hello Nikita,


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.
>


Reading the comments in this thread, the three-step approach is surprising
to some.
What about deprecating in 8.1 and removing in 9.0 instead?
The stub Serializable interface can be provided in userland via a polyfill,
if anyone really needs a smoother transition plan.

I'd really like to see this deprecation in 8.1, to stop ppl from writing
new implementations of Serializable asap.

Nicolas

---

## #113726 — Nikita Popov — 2021-03-23T17:19:22+00:00

URL: https://externals.io/message/113736#113726 · In reply to: #113724

On Tue, Mar 23, 2021 at 5:01 PM Nicolas Grekas <nicolas.grekas+php@gmail.com>
wrote:

> Hello Nikita,
>
>
> Picking up a loose thread:
> > […]
>
>
> Reading the comments in this thread, the three-step approach is surprising
> to some.
> What about deprecating in 8.1 and removing in 9.0 instead?
> The stub Serializable interface can be provided in userland via a
> polyfill, if anyone really needs a smoother transition plan.
>
> I'd really like to see this deprecation in 8.1, to stop ppl from writing
> new implementations of Serializable asap.
>

I've updated the RFC to follow this suggestion. Björn, please tell me
whether this addresses your concerns.

Regards,
Nikita

---

## #113727 — bjorn.x.larsson@telia.com — 2021-03-23T18:35:43+00:00

URL: https://externals.io/message/113736#113727 · In reply to: #113726

Den 2021-03-23 kl. 18:19, skrev Nikita Popov:

> On Tue, Mar 23, 2021 at 5:01 PM Nicolas Grekas 
> <nicolas.grekas+php@gmail.com <mailto:nicolas.grekas%2Bphp@gmail.com>> 
> wrote:
>
>     Hello Nikita,
>
>
>         Picking up a loose thread:
>         https://wiki.php.net/rfc/custom_object_serialization
>         <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
>         <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.
>
>
>
>     Reading the comments in this thread, the three-step approach is
>     surprising to some.
>     What about deprecating in 8.1 and removing in 9.0 instead?
>     The stub Serializable interface can be provided in userland via a
>     polyfill, if anyone really needs a smoother transition plan.
>
>     I'd really like to see this deprecation in 8.1, to stop ppl from
>     writing new implementations of Serializable asap.
>
>
> I've updated the RFC to follow this suggestion. Björn, please tell me 
> whether this addresses your concerns.
>
> Regards,
> Nikita
>
Yes it does, very good!

r//Björn L

---

## #113735 — come.chilliet@fusiondirectory.org — 2021-03-24T09:37:54+00:00

URL: https://externals.io/message/113736#113735 · In reply to: #113724

Le Tue, 23 Mar 2021 17:01:40 +0100,
Nicolas Grekas <nicolas.grekas+php@gmail.com> a écrit :
> Picking up a loose thread:
> > […]

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);
}

(And as I understand it, it means declaring __unserialize to do something after
parent::__unserialize() would be the same as declaring __wakeup?)

---

## #113736 — Nikita Popov — 2021-03-24T09:55:14+00:00

URL: https://externals.io/message/113736#113736 · In reply to: #113735

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 :
> > […]
> be a
> > […]
> In PHP
> > […]
>
> 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
