“__autoload() is no longer supported, use spl_autoload_register() instead”: the fix
Short answer
It’s a fatal error from PHP 8.0 and later: a very old plugin or theme defines a function called __autoload(), PHP’s first way of loading classes automatically. PHP 7.4 accepted it with a deprecation notice; PHP 8.0 refuses the whole file, so the page stops before the plugin even runs. The replacement, spl_autoload_register(), has existed since PHP 5.1. Switch PHP back if the site is down, then update or replace the plugin. A check that reads code finds it before you switch.
The message, exactly
An old gallery plugin loads its classes with __autoload(). PHP 7.4 warns and carries on; PHP 8.0 stops when it reads the file:
wp-content/plugins/old-gallery/old-gallery.php
<?php
function __autoload($class) {
require __DIR__ . '/classes/' . $class . '.php';
}
echo "Gallery plugin loaded\n";
Deprecated: __autoload() is deprecated, use spl_autoload_register() instead in /var/www/html/wp-content/plugins/old-gallery/old-gallery.php on line 2
Gallery plugin loadedFatal error: __autoload() is no longer supported, use spl_autoload_register() instead in /var/www/html/wp-content/plugins/old-gallery/old-gallery.php on line 2php.net, in the PHP 8.0 changes: “The ability to specify an autoloader using an __autoload() function has been removed. spl_autoload_register() should be used instead.” (php.net)
What it means
PHP can load a class’s file the moment the class is first used, through an autoloader. The oldest way to set one up was a function named __autoload(). PHP replaced it long ago with spl_autoload_register(), which allows several autoloaders side by side, as WordPress sites with many plugins need. PHP 8.0 removed the old way entirely, and treats a function with that name as an error in the file itself.
Fix it, in order
- Site down? Switch PHP back in your hosting panel, or pause the plugin through the link in WordPress’s email: the critical error guide.
- Find the plugin or theme from the path in the message.
- Update it, or replace it: code with
__autoload()hasn’t been maintained for years. - Your own code? The developer fix is below.
Found before you switch
The function is in the code, so a check that reads code finds it while your site still runs PHP 7.4:
Code this old often holds other PHP 8.0 removals: create_function(), each(), old-style constructors.
Key takeaways
- PHP 7.4: “__autoload() is deprecated, use spl_autoload_register() instead”, and the code ran.
- PHP 8.0 and later: a fatal error when the file is loaded, before any of its code runs.
- The replacement,
spl_autoload_register(), has been available since PHP 5.1. - Code with
__autoload()hasn’t been updated in a long time: expect other PHP 8 problems in it. - A check that reads code finds it while your site still runs PHP 7.4.
Frequently asked questions
Why does the whole plugin fail, not just one feature?
Because PHP rejects the file when it reads it, before running any line. Defining __autoload() is enough; it doesn’t even have to be called.
The plugin has no update. What now?
Code that still defines __autoload() predates PHP 7.2’s deprecation and PHP 8. Look for a maintained alternative, or have a developer modernise it; the fix itself is short.
Does WordPress use __autoload()?
No. The function comes from the plugin or theme named in the path of the message.
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.