Upgrading a Legacy PHP App to PHP 8.3: What Breaks, With Real Deprecation Output
Upgrading an old PHP application is rarely one big break. It is a pile of small ones, and the worst of them make no noise. The usual advice is to read the migration guides. This guide takes a different route: it runs a set of old-style code snippets on five real PHP versions and shows what each one actually does, so you can see which patterns break, which only warn, and which change behaviour silently.
What this article is, and is not
I ran 17 small snippets on PHP 7.4, 8.1, 8.2, 8.3 and 8.4 on one machine, with all errors switched on. Every outcome in the table is output I captured. PHP 8.0 was not installed, so I do not show it, and the "removed in 8.0" notes come from the PHP documentation and from the 7.4 and 8.1 results either side. The snippets are deliberately small and are not a real application. A real codebase also depends on its framework, extensions and libraries, which this does not test. Treat the table as a map of what to look for, and not as a complete audit.
How to reproduce it
Put each snippet in its own file, then run it under each version with errors turned on:
for v in 7.4 8.1 8.2 8.3 8.4; do
php$v -d error_reporting=-1 -d display_errors=1 -d html_errors=0 snippet.php
done
And lint a whole tree for syntax problems under the version you are moving to. Use -exec, not xargs: I found that xargs -n1 php -l stops at the first failing file, because php -l exits with status 255 and xargs aborts on that, so you would see only one of several errors.
find . -name '*.php' -exec php8.3 -l {} \; | grep -v '^No syntax errors'
What each pattern does on each version
| Pattern | PHP 7.4 | PHP 8.1 | PHP 8.2 | PHP 8.3 | PHP 8.4 |
|---|
create_function() | deprecated | fatal | fatal | fatal | fatal |
each() | deprecated | fatal | fatal | fatal | fatal |
$str{0} curly-brace offsets | deprecated | fatal | fatal | fatal | fatal |
str_contains() | fatal | works | works | works | works |
| Creating an undeclared property on an object | works | works | deprecated | deprecated | deprecated |
"${name}" in strings | works | works | deprecated | deprecated | deprecated |
utf8_encode() / utf8_decode() | works | works | deprecated | deprecated | deprecated |
Passing null to a built-in such as strlen() | works | deprecated | deprecated | deprecated | deprecated |
strftime() | works | deprecated | deprecated | deprecated | deprecated |
FILTER_SANITIZE_STRING | works | deprecated | deprecated | deprecated | deprecated |
| A float with a fraction as an array key | works | deprecated | deprecated | deprecated | deprecated |
| An optional parameter before a required one | works | deprecated | deprecated | deprecated | deprecated |
Serializable without the new methods | works | deprecated | deprecated | deprecated | deprecated |
ReflectionParameter::getClass() | works | deprecated | deprecated | deprecated | deprecated |
function f(string $s = null) | works | works | works | works | deprecated |
Reading the table from the top:
- The first group stops the application. Code using
create_function(), each() or curly-brace string offsets works, with a deprecation notice, on 7.4 and is fatal from 8.1 on. On 8.4 the curly-brace form is a parse error, so the whole file fails to load. Fix these before anything else. A linter finds them, and your tests will not if the code is never run.
- The second group works but is on notice. Dynamic properties,
${var} in strings, utf8_encode(), passing null to built-ins, strftime(), FILTER_SANITIZE_STRING, fractional array keys and the others become deprecation messages on 8.1 or 8.2. They still run today. Left alone, they flood your logs and become errors in a later major version.
- The 8.4 group. A parameter written as
string $s = null was accepted silently until 8.4, which now deprecates it and wants ?string $s = null. This is extremely common in older code.
- Going the other way,
str_contains() does not exist on 7.4, so new code written for 8.x breaks on the old version. That matters if you run both during the move, and a polyfill package fixes it.
The change with no message at all
The most dangerous differences are the ones that print nothing. One comparison I ran, 0 == "a", returns true on PHP 7.4 and false from 8.1 on. "abc" == 0 shows the same split, while comparisons such as null == false and "1" == "01" gave the same answer on every version. There is no warning, no deprecation and no error: your code simply takes a different branch. Loose comparisons between numbers and strings are common in legacy validation and permission checks, so search for them and add tests around the results. Static analysis and the test suite are the only way to catch this class, which is why a good test suite matters more than any list of deprecations.
A safer way to move
- Lint first. Run the lint loop above on the target version and fix every parse error and removed function.
- Turn deprecations on in staging, not just errors, and read the log for a representative period before you upgrade production.
- Move one version at a time. Going from 7.4 straight to 8.4 hides which step introduced a break. Testing each step costs more upfront and makes the cause obvious.
- Run your tests on the old and new versions side by side, and add tests around loose comparisons and anything involving dates, strings and numbers.
- Check your dependencies, including the framework version, for support of the target PHP version before you start. A package that does not support it will block you however clean your own code is.
- Deploy behind a switch you can undo, and watch error rates closely afterwards.
What I did not test
- PHP 8.0, and any version before 7.4.
- A real framework or application: results depend on your dependencies.
- Automated tools such as Rector or PHPStan. They can fix or flag many of these patterns, but I have not run them here, so I make no claim about what they catch.
- Performance, memory and extension behaviour.
Common mistakes
- Upgrading on a green test run alone, with tests that never touch the old code paths.
- Ignoring deprecations because "it still works".
- Jumping several versions and then having no idea where it broke.
- Forgetting that the dependencies set the limit, not your own code.
- Fixing symptoms with
@ or by lowering the error level.
Frequently asked questions
Should I upgrade straight to the newest version?
Move to the newest version your dependencies support, one version at a time, and check that version's support window before you commit.
Are deprecation notices urgent?
They are not errors today, but they are the warning list for the next upgrade. Fix them while they are cheap.
Do I need a full rewrite?
Rarely. Most legacy applications can be modernised in steps. A rewrite is slower and riskier than it looks, and it only makes sense after you have looked at the code.
Does this apply to CodeIgniter or Symfony apps?
The PHP-level changes do. The framework version and its own upgrade path are a separate question.
Where this fits
If you have an ageing PHP or Laravel application and want to know what an upgrade would involve, see Laravel & PHP Development, which covers legacy modernisation, or describe your application here. More guides on this topic are collected under PHP.