PHP 7.4 is still the most common starting point for the upgrades we are asked about. It reached community end of life in November 2022, so most of the applications still on it have now gone three years without upstream security fixes. The good news is that the path from 7.4 to a current release is well mapped. The bad news is that it crosses one large boundary, PHP 8.0, and several smaller ones that each leave a trail of deprecation notices.
This guide is the version of that map we use on enterprise codebases: what changes at each step, what to check for, and the order of work.
Before touching code: measure
Every estimate for an upgrade that went badly was made without looking. Before anyone changes a line, three things should exist:
- A compatibility report. Run PHPCompatibility (a PHP_CodeSniffer standard) against every target version, and PHPStan or Psalm at whatever level the codebase can stand. The report will be long. That is the point.
- A dependency inventory. For every Composer package, note the newest version that supports your target PHP, and flag anything abandoned. Packages with no PHP 8 release are the single biggest source of surprise cost.
- Coverage on the risky paths. You do not need a fully tested codebase. You need tests on the code the upgrade will touch: string handling, comparisons, date handling, serialization, and anything that leans on dynamic properties.
With those three, the estimate stops being a guess.
PHP 7.4 to 8.0: the big one
PHP 8.0 changed behavior that older code relied on without knowing it. The changes that cost the most time in real applications:
- String to number comparison.
0 == "foo"was true in PHP 7 and is false in PHP 8. Code that compared user input to integers, or used loose comparison inin_array()andswitch, can change behavior silently. Search for loose comparisons on mixed types and make them explicit. - Internal functions throw. Many built-in functions that used to emit a
warning and return
nullnow throwTypeErrororValueErroron bad input. Error handlers that expected warnings stop seeing them, and an exception escapes instead. - Removed functions.
create_function(),each()and several others are gone. Static analysis finds them all. - The
@operator no longer hides fatal errors. Code that suppressed errors on risky calls can now stop the request. - Stricter arithmetic and array access. Arithmetic on arrays, resources or objects throws. Reading an undefined array key or property is a warning, not a notice, which often floods logs on day one.
Most of this work is mechanical once found. Rector automates a large share of it, and the rest is careful hand work on the comparisons.
PHP 8.0 to 8.1
8.1 is mostly additive, but it introduced deprecations that show up everywhere:
- Passing
nullto non-nullable internal parameters is deprecated.strlen(null)and friends now emit notices. In older codebases this is often the noisiest change of the entire upgrade. - Return type declarations on internal methods. Classes that extend built-in
classes such as
ArrayAccessorIteratorimplementations get deprecation notices until their method signatures match, or carry the#[\ReturnTypeWillChange]attribute. - The
Serializableinterface is deprecated without__serialize()and__unserialize().
PHP 8.1 to 8.2
- Dynamic properties are deprecated. Assigning a property that was never
declared now emits a notice, unless the class allows it with
#[\AllowDynamicProperties]. Legacy code, and plenty of older libraries, does this constantly. ${var}string interpolation is deprecated in favor of{$var}.utf8_encode()andutf8_decode()are deprecated.
Declaring the properties a class actually uses is the right fix, and it doubles as documentation for the next person.
PHP 8.2 to 8.3, 8.4 and 8.5
The later steps are smaller. 8.3 adds typed class constants and tightens a few
edge cases. 8.4 deprecates implicitly nullable parameter types, where a typed
parameter defaults to null without a ? in its type, which is common in
older code, and removes E_STRICT. 8.5 continues the cleanup. By this point a
codebase that cleared its 8.1 and 8.2 deprecations usually moves in days, not
weeks.
The order of work that holds up
- Cover the runtime first. If the current version is past end of life, put it under long-term support before the project starts. The security finding closes now, and the upgrade stops being a race.
- Fix forward on the old version. Clear what can be fixed while still on 7.4: dynamic properties, null arguments, loose comparisons. Ship those changes to production on the old runtime.
- Upgrade dependencies next, one at a time, to versions that support both the old and the new PHP where possible.
- Run CI on both versions. Keep the target version in CI from early on, so the suite tells you how far there is to go.
- Flip the runtime per environment. Development, then staging, then a slice of production, with the rollback tested before it is needed.
- Clear the deprecations you deferred, so the next upgrade is smaller.
What this costs
Effort depends on the size of the codebase, how much of it is covered by tests, and how many dependencies have no future. Those three numbers come out of the measuring step. That is why every upgrade we run starts there, and why the estimate that follows is one we are willing to be held to.