“implements the Serializable interface, which is deprecated”: what it means and the fix
Short answer
It’s a deprecation notice from PHP 8.1 and later: a class in a plugin or theme implements PHP’s old Serializable interface, used to store objects in sessions, caches or the database, without the newer __serialize() and __unserialize() methods. The code keeps working, and PHP shows the notice when the file loads. PHP’s message names the fix: add the two new methods, alongside the old ones if the plugin still supports PHP older than 7.4. Update the plugin, or send the message to its developer.
The message, exactly
A cart plugin stores its cart in the session through Serializable. PHP 8.0 loads it silently; PHP 8.1 adds the notice as soon as the class is loaded:
wp-content/plugins/cart-session/cart.php
<?php
class Cart implements Serializable {
private $items = [];
public function serialize() {
return serialize($this->items);
}
public function unserialize($data) {
$this->items = unserialize($data);
}
}
echo 'Loaded', "\n";
LoadedDeprecated: Cart implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /var/www/html/wp-content/plugins/cart-session/cart.php on line 2
Loadedphp.net, in the PHP 8.1 deprecations, on implementing Serializable without the new methods: “Either only the new methods should be implemented, if no support for PHP prior to version 7.4 is provided, or both should be implemented.” (php.net)
What it means
To store an object as text (in a session, a cache, the database), PHP serialises it. Classes could control that with the Serializable interface and its serialize() and unserialize() methods. PHP 7.4 introduced a better pair, __serialize() and __unserialize(). From PHP 8.1, a class that has only the old pair gets this notice.
Who fixes it
- Find the plugin or theme: the folder after
wp-content/plugins/orwp-content/themes/in the message; the class name helps too. - Update it (Dashboard → Updates).
- Already on the latest version? Send one line of the message to its developer.
- Meanwhile, keep notices off your pages: the WordPress debug log.
Found before you switch
The class declaration is in the code, so a check that reads code finds it while your site still runs PHP 8.0:
The other PHP 8.1 changes: WordPress and PHP 8.1.
Key takeaways
- A deprecation notice from PHP 8.1 and later; objects are still saved and loaded as before.
- It appears when the class is loaded, once per class, even if nothing is serialised on that page.
- The fix: add
__serialize()and__unserialize(); keep the old methods only for PHP older than 7.4. - With both pairs present, PHP 8.1 and later use the new methods and stay quiet.
- A check that reads code finds these classes before you upgrade.
Frequently asked questions
Will my carts, sessions or caches break?
No. On PHP 8.1 to 8.5 the old methods still work; the notice only marks them for replacement. A future PHP version may remove the old interface, which is why the plugin should add the new methods.
Why does the notice appear on pages that don’t use the class?
PHP checks the class when it loads the file. If the plugin loads that file on every page, the notice appears on every page, even when nothing is stored.
Does adding the new methods change stored data?
New values are stored in the new format. Values stored earlier are still read, as long as the class keeps implements Serializable and its old unserialize(): in our test on PHP 8.1, a class with both pairs loaded an old value correctly, while a class with only the new methods lost its contents.
Check your own site before you upgrade
CompatNav is a free WordPress plugin. It reads the code of your plugins and themes on your own server and tells you, in plain words, what will break and what will only show notices on the PHP version you choose. It never changes your code. It can’t see problems that only appear while code runs with real data, so a quick check of your site after the upgrade still matters.
Sources
About the code examples: each output is the real output of the code shown, run with the official PHP builds, without a php.ini, with all errors reported and displayed. Only the file path was replaced by a neutral server path.