Source. This article is based on PHP manual: Migrating from PHP 7.4.x to PHP 8.0.x, backward incompatible changes. Details were checked against it on November 4, 2026; check the source for later changes.
After an upgrade to PHP 8 the error log fills with lines like these:
PHP Warning: Undefined variable $total in /var/www/shop/cart.php on line 88
PHP Warning: Undefined array key "email" in /var/www/shop/checkout.php on line 41
PHP Warning: Attempt to read property "name" on null in /var/www/shop/header.php on line 12
None of them stops the page, so they are easy to dismiss. They should not be. The PHP 8.0 incompatible changes say that a number of notices have been converted into warnings, including reading an undefined variable, an undefined property, an undefined array key and a property of a non-object. It is the same code with a higher severity.
Why a warning matters
- Broken output. If
display_errorsis on, the warning is printed into the page. On an AJAX or API response that makes the JSON invalid, and on any page that has already sent headers it can trigger a second error. - Warnings turned into exceptions. Some frameworks and custom error handlers convert warnings into exceptions. Code that used to run with a notice then stops.
- Noise hides real problems. A log with tens of thousands of warnings a day makes it hard to see the one failure that matters.
- They point at real bugs. A missing key often means a form field or a database column was not what the code expected.
See them before PHP 8 does
Because these were notices before, you can find them on the old version. Set full reporting on a staging copy, keep display off and log to a file:
php.ini on the staging copy
error_reporting = E_ALL
display_errors = Off
log_errors = On
Then rank the messages by how often they appear, so you fix the loudest first. PHP 7 words the array case as "Undefined index" or "Undefined offset", and PHP 8 as "Undefined array key", so the search covers both:
grep -E "Undefined (variable|index|offset|array key)|Trying to access array offset|Attempt to read property" php-error.log | sed -E 's/^\[[^]]*\] //' | sort | uniq -c | sort -rn | head -50
Fix each pattern properly
Undefined variable
The variable is used on a path where nothing set it, such as a total assigned only inside an if or a loop. Give it a starting value before the branch:
$total = 0;
foreach ($items as $item) {
$total += $item['price'];
}
Undefined array key
This is usually input that may be missing: $_GET, $_POST, a database row or a config array. The null coalescing operator, added in PHP 7.0, supplies a default:
// before
$email = $_POST['email'];
// after (PHP 7.0 and later)
$email = $_POST['email'] ?? '';
// after (PHP 5.6)
$email = isset($_POST['email']) ? $_POST['email'] : '';
Attempt to read property on null
Something that should be an object is null, typically because a lookup found nothing. Check it before use. PHP 8.0 added the nullsafe operator (?->), which returns null instead of warning:
$name = $user?->name ?? 'Guest';
Use it where "no value" is a normal outcome. Where a missing object means something went wrong, check explicitly and handle it, or the operator hides the very bug the warning pointed at.
Array offset on a non-array
This is reading $value['key'] when $value is null or false, often after a failed query. The manual lists "attempting to access an array index of a non-array" among the converted notices. Check is_array($value) first.
What not to do
Resist putting @ in front of everything. Turning display_errors off in production, so visitors never see warnings while they are still logged, is reasonable. Lowering error_reporting to hide them from the log as well is not, because you lose the list you need to work through.
Test and follow up
After each batch of fixes, exercise the affected pages with complete and incomplete input, since the incomplete case is what raised the warning. Our guide to adding tests to legacy PHP code covers how to lock that in. We have not run these changes on your code, so check them on a copy first.
A large legacy platform can produce thousands of distinct warnings. Our legacy system support work triages them by frequency and fixes the patterns, not the individual lines. Related errors: count() TypeError in PHP 8 and Passing null to parameter deprecations in PHP 8.1.
Frequently asked questions
Are PHP 8 warnings fatal?
No. A warning does not stop the script. It can still corrupt output such as JSON, or become an exception if a custom error handler converts warnings.
What is the difference between Undefined index and Undefined array key?
It is the same condition. PHP 7 reported an undefined index or offset as a notice. PHP 8 reports an undefined array key as a warning; the manual lists it among the notices converted into warnings.
Does the null coalescing operator work on PHP 5.6?
No. The ?? operator was added in PHP 7.0. On PHP 5.6 use isset() with a ternary expression.
Log full of warnings after the upgrade?
We triage the warnings, fix the patterns behind them and leave you with a clean log on a supported PHP version.
See our Legacy System Support