article
Why every PHP upgrade breaks something in your code
Why PHP upgrades break old code - removed functions, stricter type handling and deprecations - why PHP can afford to break backwards compatibility, and how to prepare your applications.
As a hosting provider I regularly bump the PHP version for dozens of client sites, and almost every time something stops working. A plugin throws an error, an old custom script shows a blank page, or a log file fills up with deprecation notices.
Right now that’s topical again: according to php.net, PHP 8.2 stops receiving security fixes on 31 December 2026. Anyone still running it has a few weeks to move.
So why does PHP keep doing this? Other languages seem to get away with far fewer breaking changes. Part of the answer is PHP’s history. The other part is something people tend to overlook.
A house without a blueprint
PHP didn’t start out as a programming language. Rasmus Lerdorf wrote it in the mid-nineties as a set of helper scripts for his own homepage. The name originally stood for Personal Home Page Tools, and it grew into a language one feature at a time.
I think of it as a house people were already living in before anyone drew a blueprint. Rooms were added wherever they fitted. Making a house like that safe means ripping out old wiring, and whatever was plugged into it goes with it.
Clearing out the junk
Some of that wiring was outright dangerous:
register_globalsturned request parameters into variables automatically, a steady source of security holes.magic_quotesescaped quotes to prevent SQL injection, but mostly gave a false sense of security.safe_modepromised isolation it never really delivered.
All three were removed in PHP 5.4. PHP 7.0 then dropped the old mysql_*
functions (replaced by mysqli and PDO) and ereg (replaced by the PCRE
preg_* functions). PHP 8.0 removed each() and create_function(). Each
removal broke the code that still relied on it.
Getting stricter
For a long time PHP was very forgiving. When something went wrong you got a
warning at most, and the script carried on, often with a strange result.
Since PHP 7, and especially PHP 8, many of those silent failures throw
errors such as TypeError or ValueError. Strictly speaking those extend
Error, not Exception, so a catch (Exception $e) won’t catch them.
The classic example: before PHP 8.0, 0 == "foo" evaluated to true. Now
it’s false. Code that depended on this never worked properly, you just
couldn’t see it. In that sense an upgrade often doesn’t break your code. It
shows you where it was already broken.
Minor versions join in
The convention is that a feature is first marked deprecated and only removed in a later major version. But deprecations land in minor versions too:
- PHP 8.1: passing
nullto internal functions that don’t accept it - PHP 8.2: dynamic properties on objects
- PHP 8.4: implicitly nullable parameters
Deprecated isn’t removed, so the code usually keeps running. You do get a stream of notices in your logs, and some frameworks and plugins convert those notices into exceptions. Then even a deprecation can take a site down before anything has actually been removed.
Why PHP can break backwards compatibility
Compare it with JavaScript in the browser. Browser vendors work by the rule don’t break the web: they can hardly ever remove a feature, because some site from 2003 still depends on it. And visitors can’t choose which version of JavaScript their browser runs.
With PHP, the server owner picks the version. Old code that can’t handle PHP 8? Stay on an older version for a while. That’s exactly what gives PHP’s developers room to clean up the language, something browser vendors have to be extremely careful about.
It also matters that no single company owns PHP. Companies like Zend have contributed developers and funding for decades, but none of them controls the language or its compatibility policy. Since 2021 the PHP Foundation helps fund core development.
You can’t stay put forever
That freedom has a limit. A new PHP version comes out every November. Each one gets two years of active support and then two years of security fixes only. After four years you’re on your own.
The pace is deliberate. It stops the ecosystem getting stuck on ancient versions, as it did for years in the PHP 5 era.
Upgrading without surprises
Modern PHP code, with types, Composer-managed dependencies and a maintained framework, usually gets through an upgrade without much trouble. The pain is almost always in old custom code and in WordPress plugins nobody has updated in years.
What saves me the most time:
- Scan first. PHPCompatibility, a ruleset for PHP_CodeSniffer, checks your code against a specific PHP version before you switch.
- Let Rector do the boring part. Rector automates many common migration changes. Not everything, but it saves a lot of manual fixing.
- Test against the target version. Run a staging copy on the version
you’re moving to and log
E_DEPRECATEDandE_USER_DEPRECATED. Not every notice becomes a fatal error in the next release, but each one points at code that needs attention. - Switch per site, not per server. Plesk lets you pick a PHP version per domain. Without a panel you get the same thing with a separate php-fpm pool per site, running each PHP version as its own php-fpm service (Remi’s packages for AlmaLinux make that easy). Move a staging copy first, check the logs, then switch the live site.
You don’t need the newest release either. A supported version your application runs well on beats a blind jump to the latest one.
Annoying as it is, PHP’s habit of breaking things is also how a messy set of homepage scripts turned into a language you can build serious software on.