Take the State of PHP 2026 Survey →

Phasing out Serializable View as Markdown

Accepted
Authors
Nikita Popov nikic@php.net
Date
2020-12-07
Target
PHP 8.1
Implementation
https://github.com/php/php-src/pull/6494
Source
wiki.php.net/rfc/phase_out_serializable

Vote

Phase out Serializable as proposed? closed
Yes
36
No
0
36 voters
asgrim Yes 2021-04-16 08:51
ashnazg Yes 2021-04-14 15:46
brzuchal Yes 2021-04-14 10:10
bwoebi Yes 2021-04-15 17:43
crell Yes 2021-04-14 15:09
cschneid Yes 2021-04-14 08:56
daverandom Yes 2021-04-21 21:45
derick Yes 2021-04-26 08:17
ekin Yes 2021-04-23 19:08
galvao Yes 2021-04-16 14:18
girgias Yes 2021-04-14 11:38
kalle Yes 2021-04-15 15:50
kguest Yes 2021-04-19 11:54
kinncj Yes 2021-04-22 21:42
kocsismate Yes 2021-04-14 08:26
lcobucci Yes 2021-04-15 10:43
lufei Yes 2021-04-19 09:52
marandall Yes 2021-04-14 10:28
narf Yes 2021-04-14 11:23
nicolasgrekas Yes 2021-04-19 15:23
nikic Yes 2021-04-14 08:21
ocramius Yes 2021-04-19 16:06
patrickallaert Yes 2021-04-14 09:07
pierrick Yes 2021-04-14 13:14
ramsey Yes 2021-04-14 13:05
reywob Yes 2021-04-14 15:04
sammyk Yes 2021-04-24 19:22
santiagolizardo Yes 2021-04-14 11:33
sebastian Yes 2021-04-14 08:30
sergey Yes 2021-04-14 08:29
sirsnyder Yes 2021-04-14 11:47
svpernova09 Yes 2021-04-14 15:26
tandre Yes 2021-04-22 14:02
theodorejb Yes 2021-04-14 12:53
trowski Yes 2021-04-15 21:12
twosee Yes 2021-04-19 06:54

Discussions on the mailing list

[RFC] Phasing out Serializable
by Nikita Popov · 9 messages
[VOTE] Phasing out Serializable
by Nikita Popov · 2 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:50 UTC

Introduction

The new custom object serialization mechanism RFC introduced new __serialize() and __unserialize() magic methods in PHP 7.4, with the intent of replacing the broken Serializable interface. This RFC finalizes that work by laying out a plan for the eventual removal of Serializable.

Please see the referenced RFC for a detailed discussion of why the Serializable interface is broken and needs to be replaced. Since PHP 7.4 a robust alternative mechanism exists, but some of the motivating issues will only be resolved once support for Serializable is dropped entirely.

Proposal

Serializable

A class is “only Serializable” if it is non-abstract, implements Serializable, and does not implement __serialize() and __unserialize(). Then:

  • In PHP 8.1, declaring an “only Serializable” class will throw a deprecation warning. Other implementations of Serializable will be accepted without a deprecation warning, because libraries supporting PHP < 7.4 will generally need to implement both the old and new mechanisms.
  • In PHP 9.0 the Serializable interface will be removed and unserialize() will reject payloads using the C serialization format. Code needing to support both PHP < 7.4 and PHP >= 9.0 may polyfill the Serializable interface, though it will have no effect on serialization.

If a class implements both Serializable and __serialize()/__unserialize(), the latter take precedence (on versions that support them), and the Serializable interface is only used to decode existing serialization payload using the obsolete C format. To migrate to the new mechanism, it's possible to either replace Serializable entirely (if support for PHP 7.3 and below is not needed) or to implement both (if it is needed).

An earlier version of this RFC proposed an additional step: PHP 9.0 would deprecate all uses of Serializable (including those that are not “only Serializable”) and only remove the interface in PHP 10.0. However, this approach was deemed too complicated.

PDO::FETCH_SERIALIZE

PDO has a PDO::FETCH_SERIALIZE flag that can be used in conjunction with PDO::FETCH_CLASS. This fetch mode is based on the Serializable interface, and as such it cannot be supported once it is removed. Apparently, the PDO::FETCH_SERIALIZE mode is not actually usable due to an implementation bug (https://bugs.php.net/bug.php?id=68802) anyway.

In addition to the Serializable changes, this RFC proposes to deprecate PDO::FETCH_SERIALIZE in PHP 8.1 and remove it in PHP 9.0.

Vote

Voting started 2021-04-14 and ended 2021-04-28.

Vote: Phase out Serializable as proposed? — Yes: 36 · No: 0 (closed)