After a PHP upgrade, lines like these start appearing at the top of your pages or filling the error log:
Deprecated: Creation of dynamic property Order::$total is deprecated in /var/www/app/src/Order.php on line 3
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/app/src/Cart.php on line 4
The quick fix most people search for is "how do I hide PHP deprecated warnings". You should hide them from visitors, today. But a deprecation is advance notice that the code will break in a future PHP version, so the real job is to hide them in production, collect them somewhere, and fix them on your schedule. This guide does both, for plain PHP, WordPress and Laravel.
What "Deprecated" means
A deprecation is not an error. The code still runs and does the same thing it did before. PHP is telling you that a feature will be removed or changed in a later version, at which point the line becomes a real error. The messages above came from a test script on PHP 8.3; every one of them still ran.
So deprecations are:
- Harmless today, apart from the noise and the information they leak when shown on a page.
- A to-do list for your next PHP upgrade. Fix them before you move to a version that removes the feature.
Step 1: stop showing errors to visitors
If deprecation messages appear on your pages, the real problem is that display_errors is on in production. That shows every warning and error, including file paths, to anyone. Turn it off and log instead.
PHP's own recommended production settings, from php.ini-production:
display_errors = Off
log_errors = On
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
On PHP 8.4 and later, leave out & ~E_STRICT; that constant is deprecated itself.
On a VPS with PHP-FPM, you can set these per site in the pool file (for example /etc/php/8.4/fpm/pool.d/www.conf), which overrides php.ini and can't be changed by the application:
php_admin_flag[display_errors] = off
php_admin_flag[log_errors] = on
php_admin_value[error_log] = /var/log/php/example.com-error.log
Create the log folder, make it writable by the pool's user, and reload: sudo systemctl reload php8.4-fpm.
Excluding E_DEPRECATED in production is fine as long as you collect deprecations somewhere else, such as staging or CI. That's step 3.
WordPress
WordPress controls error reporting itself through wp-config.php. For production:
define( 'WP_DEBUG', false );
With WP_DEBUG off, WordPress sets its own error level, which leaves out deprecations and notices. If you still see "Deprecated" on a WordPress site, check:
WP_DEBUGistrue, left over from debugging. For a site where you want the log but not the display, use:
Block public access todefine( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); // writes to wp-content/debug.log define( 'WP_DEBUG_DISPLAY', false ); @ini_set( 'display_errors', 0 );debug.logor setWP_DEBUG_LOGto a path outside the web root, because it can contain sensitive details.- The message appears before WordPress loads, for example from
wp-config.phpitself or a file loaded very early. Then only the server'sdisplay_errorssetting applies, so fix it at the PHP level as in step 1. - A plugin calls
error_reporting()and turns everything on. Search your plugins folder forerror_reporting(.
Laravel
Laravel catches deprecations separately from other errors and sends them to a "deprecations" log channel. In config/logging.php:
'deprecations' => [
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
'trace' => env('LOG_DEPRECATIONS_TRACE', false),
],
The default channel is null, which discards them, so a standard Laravel app doesn't show or log deprecations at all. To collect them on staging or locally, set:
LOG_DEPRECATIONS_CHANNEL=single
LOG_DEPRECATIONS_TRACE=true
They then go to storage/logs/laravel.log with a stack trace showing which of your files triggered them, which matters because many deprecations come from inside vendor packages.
Step 3: collect them and see what you're dealing with
On a staging copy, or in your test suite, turn everything on:
php -d error_reporting=-1 -d display_errors=0 -d log_errors=1 \
-d error_log=/tmp/deprecations.log vendor/bin/phpunit
Logs repeat the same message thousands of times. This shows each distinct deprecation once, with how often it occurred and in which file:
grep -o 'PHP Deprecated: .*' /tmp/deprecations.log \
| sed 's/ on line [0-9]*//' | sort | uniq -c | sort -rn | head -20
Most of the time a long list turns out to be a handful of causes, often one outdated plugin or package. Update that first: the maintainer has frequently fixed it already.
Step 4: fix the common ones
| Message | Since | Fix |
|---|---|---|
| Creation of dynamic property X::$y is deprecated | 8.2 | Declare the property in the class (public ?float $total = null;). For classes that really need dynamic properties, add #[\AllowDynamicProperties] above the class. |
| strlen(): Passing null to parameter #1 ($string) of type string is deprecated | 8.1 | The value is null where a string is expected. Default it: strlen($name ?? ''), or find why it's null. |
| Using ${var} in strings is deprecated, use {$var} instead | 8.2 | Change "Hi ${name}" to "Hi {$name}". |
| Function utf8_encode() is deprecated | 8.2 | Use mb_convert_encoding($s, 'UTF-8', 'ISO-8859-1'). |
| Implicitly marking parameter $x as nullable is deprecated | 8.4 | Change string $x = null to ?string $x = null. See our full guide. |
Tools can do much of this automatically. Rector has rule sets per PHP version that rewrite code, for example adding the ? to nullable parameters across a whole project. Review its changes like any other pull request.
If the deprecation is in a plugin or package you don't control
- Update it. Then check its changelog or issue tracker for the message.
- If it's maintained, open an issue with the exact message and PHP version.
- If it's abandoned, plan to replace it before your next PHP upgrade. Deprecated today means broken in a future version, and nobody is going to fix it for you.
Don't edit files inside vendor/ or wp-content/plugins/ to silence a message. The next update overwrites your change.
FAQ
Is it safe to ignore deprecation warnings?
For now, yes: the code works. Ignoring them indefinitely isn't, because the next major PHP version can turn them into fatal errors. Hide them from visitors, but keep a list and fix it before upgrading.
Do deprecation warnings slow down my site?
Slightly, when they're reported. Logging thousands of the same message per request costs disk I/O and can fill a disk; see fixing "No space left on device" if a log has already grown out of control.
Why do I see deprecations after a PHP upgrade but not before?
Each PHP version deprecates new things. Upgrading from 8.3 to 8.4, for instance, adds the implicitly nullable parameter deprecation, which affects a lot of older WordPress plugins. If you're upgrading from 8.2 because it reaches end of life on December 31, 2026, our PHP 8.2 upgrade guide covers the rest of the move.
Bottom line
Turn off display_errors in production and log instead; leave deprecations out of the production error level if you collect them elsewhere. In WordPress keep WP_DEBUG off on live sites; in Laravel, deprecations are discarded unless you set LOG_DEPRECATIONS_CHANNEL. Then gather them on staging, group them, update the packages causing them and fix the rest before your next PHP upgrade.
Messages reproduced with PHP 8.3 on 2 November 2026. Settings checked against php.ini-production, the WordPress debugging documentation and Laravel 13's default logging config.
Comments 0
Be the first to comment.
Leave a comment