PHP Deprecated in error_log after a PHP upgrade, what it means and how to stop it

A PHP Deprecated message means that your site's code uses something the new PHP version still accepts but will remove in a future version. It is not a server error and the site usually works normally. The right fix is to update the application, theme or plugin responsible, and until then you limit logging from the application's settings or from PHP Selector so that the error_log does not fill up.

What does a PHP Deprecated message mean

A typical message in the PHP error log looks like this:

PHP Deprecated:  html_entity_decode(): Passing null to parameter #1 ($string) of type string is deprecated in /home/.../catalog/controller/product/product.php on line 120

You read it in three parts:

  • what is being used in a way that will be removed, here the html_entity_decode() function with an empty value (null),
  • where, meaning the file and the line,
  • who is responsible, which you can tell from the path. A wp-content/plugins/plugin-name/ path points to a plugin, a wp-content/themes/ path points to a theme.

Deprecated is a warning about the future. It is different from a PHP Fatal error, which stops the page, and from a PHP Warning, which points to an actual problem in how the code runs.

Why did they appear after the PHP upgrade

Every new PHP version marks old ways of writing code as deprecated. Code written for an older version starts producing messages without having changed itself. It is a matter of the code's compatibility with the new version.

The most common PHP 8 deprecated messages per version:

Version What you see in the log
8.1 Passing null to parameter #1 ... is deprecated, meaning an empty value passed to a function that expects text or a number. Also Return type of ... should either be compatible with ... in classes
8.2 Creation of dynamic property ... is deprecated, meaning a property that has not been declared in the class. Also utf8_encode() and utf8_decode()
8.4 Implicitly marking parameter ... as nullable is deprecated, meaning a parameter with a null default and no declared ? type
8.5 Old type cast forms such as (boolean), (integer), (double), the backtick operator for commands, a case ending with ; instead of :, null as an array key

The PHP 8.2 deprecated message "creation of dynamic property is deprecated" is one of the most frequent in old plugins and themes. The PHP 8.4 deprecated message about nullable parameters shows up mostly in libraries that have not been updated. Anything marked deprecated is meant to be removed in a future major PHP version. At that point the same code will produce an error and the site may stop working. That is why these messages are worth fixing, not just hiding.

Why it is not a server problem

PHP behaves as its version defines. The message is caused by the code of the application, the theme or a plugin, and it would appear in exactly the same way on any server running the same PHP version. At Konet, PHP Selector runs with its default settings. Going back to an old version stops the messages, but old versions no longer receive security updates. See how to change the PHP version with PHP Selector.

The right fix, updating the application

  1. Open the error_log from cPanel > Files > File Manager or see the recent messages in cPanel > Metrics > Errors. See the guide to cPanel Errors.
  2. Work out from the path which plugin, theme or part of the application is responsible.
  3. Update that plugin or theme to its latest version. Most developers have already fixed the PHP 8.1 and 8.2 messages.
  4. If there is no newer version, send the log lines to the developer or to your programmer.
  5. Delete the error_log and check after a few hours whether it is being written again.

Fixing code, plugins and themes is the responsibility of the site administrator and is not included in hosting support. See what hosting support covers.

How do I limit logging from within the application

Many applications decide for themselves what gets logged, and then the application's setting takes priority over PHP. That is why you start there.

  • WordPress. WordPress deprecated messages are usually logged when WP_DEBUG is enabled. Open wp-config.php and find the line define( 'WP_DEBUG', true );. On a site that works normally, change it to false. With WP_DEBUG off, WordPress does not log Deprecated and Notice messages. If WP_DEBUG_LOG is enabled, messages are written to wp-content/debug.log, which grows as well.
  • OpenCart. Log in to the admin panel, go to System > Settings, edit the store and open the Server tab. There you set Display Errors and Log Errors.
  • Joomla. Under System > Global Configuration > Server, the Error Reporting setting defines what is shown.

How do I limit logging from PHP Selector

PHP Selector has settings for PHP messages in the Options tab.

  1. Open cPanel > Software > Select PHP Version.
  2. Go to the Options tab.
  3. In error_reporting you set which types of messages are logged, by choosing from the values in the list. If you are not sure which value excludes Deprecated messages (E_DEPRECATED), ask your programmer.
  4. Make sure display_errors is off, so that messages are not shown to visitors.

Changes take effect immediately. If you change the PHP version later, check the Options tab again. If the Options tab shows a message about the native version, the account is on the server default. First choose a numbered version and click Set as current.

The php.ini and .user.ini files, as well as the MultiPHP INI Editor, have no effect at Konet. For other PHP settings see the guide to PHP settings with .htaccess.

How do I stop the error_log from filling up the space again

A site with many Deprecated messages writes a few lines on every visit. Within a few weeks the error_log can reach gigabytes and fill the plan's disk space, and then email stops too.

  • You can delete the error_log from File Manager with no effect at all on the site. It will be created again when a new message appears.
  • After changing the setting, check that the file now grows slowly.
  • The size of folders and files is shown in cPanel > Files > Disk Usage. See the Disk Usage guide.

Frequently Asked Questions

I didn't have these messages before the migration, why now?
Most likely the site now runs on a newer PHP version or with a different logging setting in the application. Check the version in Select PHP Version and the application's debug setting, for example WP_DEBUG.

If I hide the Deprecated messages, is the site at risk?
Not immediately. Hiding them does not change how the site works, only what is logged. The code will still need fixing before the next major PHP upgrade becomes possible.

I changed the setting but the log is still being written. Why?
The application may set its own logging, see the section for WordPress, OpenCart and Joomla. Or the new messages may be Warning or Notice messages, which need fixing. WordPress also logs database errors on its own (WordPress database error).

Should I go back to an older PHP version to stop them?
Only as a temporary fix if the site does not work. Old versions get no security updates from PHP. Prefer updating the application.

The same log also shows "MySQL server has gone away". Is it related?
Not to the Deprecated messages. It means the connection to the database was lost during a query. If it started after a PHP change, check in the Extensions tab of Select PHP Version that the database extensions the application needs are enabled, such as mysqli, mysqlnd and pdo_mysql. If it continues, open a ticket with the time and the page.

I want to see errors on screen so I can fix them. Is that possible?
Yes, with display_errors in Options, but only briefly and ideally on a copy of the site. On-screen messages show everyone file paths and information about the code. Turn it off as soon as you are done.

Was this article helpful?

Related service Konet Web Hosting cPanel, LiteSpeed and automatic backups: 24 every 2 hours for 48 hours, then 6 daily, 4 weekly and 3 monthly.