What is E_DEPRECATED in PHP, and how to handle it in WordPress

By CompatNav · Published · Last reviewed · 4 min read

Short answer

E_DEPRECATED is one of PHP’s error levels: the one for deprecation notices, messages about code that still works but will not work in a future PHP version. Its sibling E_USER_DEPRECATED is the same for messages that code raises itself, which is how WordPress announces its own outdated functions. While WP_DEBUG is off, WordPress doesn’t report either level; with WP_DEBUG on, it reports everything. Handle them by logging, not displaying, and by fixing them through plugin and theme updates before the PHP version that removes the feature.

What E_DEPRECATED is

PHP sorts its messages into levels, each a constant with a number. php.net describes E_DEPRECATED as: “Run-time deprecation notices. Enable this to receive warnings about code that will not work in future versions.” (php.net)

So a deprecation notice is PHP saying: this still works, but plan for the day it won’t. Every PHP version deprecates a few things, and a later version removes some of them. PHP 8.0, for example, removed functions that 7.2 to 7.4 had deprecated, such as create_function() (the list).

The levels you’ll meet in WordPress

LevelValueWhat it means for a page
E_ERROR1Fatal error: the page stops
E_WARNING2Something went wrong, the page continues
E_NOTICE8A minor issue, the page continues
E_DEPRECATED8192Works now, won’t in a future PHP version
E_USER_DEPRECATED16384The same, raised by code such as WordPress
E_ALL30719 (32767 before PHP 8.4)Every level together

php.net on the user-level twin: “User-generated deprecation message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error().” And on E_ALL, whose value it gives as 30719: “Prior to PHP 8.4, the constant value was: 32767” (php.net). We checked both values on the official PHP 7.4, 8.0, 8.4 and 8.5 builds. More on the level PHP 8.4 dropped: “Constant E_STRICT is deprecated”.

Both kinds, and how they’re filtered

A plugin calls utf8_encode(), deprecated by PHP 8.2 (E_DEPRECATED), and one of its own old functions announces itself the way WordPress does (E_USER_DEPRECATED). Reported with E_ALL, both show; with both levels left out, neither does, and the code runs the same:

wp-content/plugins/old-importer/import.php

<?php
// Every message level reported (what WP_DEBUG does):
error_reporting(E_ALL);
echo utf8_encode('Caf'), "\n";
trigger_error('Function old_import() is deprecated since version 2.0!', E_USER_DEPRECATED);

// Deprecation messages left out (what WordPress does while WP_DEBUG is off):
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
echo utf8_encode('Caf'), "\n";
trigger_error('Function old_import() is deprecated since version 2.0!', E_USER_DEPRECATED);
echo "Done\n";

Output on PHP 8.2.34

Deprecated: Function utf8_encode() is deprecated in /var/www/html/wp-content/plugins/old-importer/import.php on line 4
Caf

Deprecated: Function old_import() is deprecated since version 2.0! in /var/www/html/wp-content/plugins/old-importer/import.php on line 5
Caf
Done

Output on PHP 8.5.11

Deprecated: Function utf8_encode() is deprecated since 8.2, visit the php.net documentation for various alternatives in /var/www/html/wp-content/plugins/old-importer/import.php on line 4
Caf

Deprecated: Function old_import() is deprecated since version 2.0! in /var/www/html/wp-content/plugins/old-importer/import.php on line 5
Caf
Done

How WordPress handles them

WordPress sets PHP’s error level itself, depending on WP_DEBUG (WordPress 7.1.2 source):

  • WP_DEBUG on: E_ALL, every level, deprecation notices included.
  • WP_DEBUG off: a list of levels without notices and without either deprecation level:

wp-includes/load.php · WordPress 7.1.2, wp_debug_mode(), the level used while WP_DEBUG is off

error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );

WordPress’s own outdated functions announce themselves with E_USER_DEPRECATED, and only while WP_DEBUG is on and the deprecated_function_trigger_error filter allows it (WordPress 7.1.2 source). Their message names a WordPress version, not a PHP version.

How to handle them

  1. On the live site, keep WP_DEBUG off. Visitors never see deprecation notices, and WordPress doesn’t even report them.
  2. On a staging copy, log everything: WP_DEBUG and WP_DEBUG_LOG on, WP_DEBUG_DISPLAY off (the WordPress debug log).
  3. Group the log by plugin or theme, using the path in each message, and update what has an update.
  4. Send the rest to the developers. A notice is not urgent, but it is a deadline without a date.

For what each level does to a page, with examples: deprecation notice or fatal error.

Find them before the next PHP version

The deprecations a PHP upgrade brings are in your plugins’ code before you switch. CompatNav, a free plugin on wordpress.org, lists them per plugin and theme for the PHP version you choose (8.0 to 8.5), labelled “Deprecation notice”, separately from what will break:

Key takeaways

  • E_DEPRECATED (8192): deprecation notices from PHP itself, for code a future PHP version won’t accept.
  • E_USER_DEPRECATED (16384): deprecation messages raised by code, including WordPress’s own.
  • With WP_DEBUG off, WordPress leaves both out; with WP_DEBUG on, it reports E_ALL.
  • E_ALL itself changed in PHP 8.4: 30719 instead of 32767, because E_STRICT was taken out.
  • Handle them by logging on a staging copy, and fix them through updates before the next PHP version.

Frequently asked questions

Is E_DEPRECATED an error?

No. It’s a level of message, the mildest that matters: the code runs normally. Only a fatal error stops a page.

Should I turn E_DEPRECATED off on my live site?

WordPress already does while WP_DEBUG is off, which is the right setting for a live site. Keep the messages visible somewhere, in a debug log on a staging copy, so you know what to fix.

How do I stop WordPress’s own deprecation messages?

They only appear with WP_DEBUG on. A developer can switch off the ones for deprecated functions with the deprecated_function_trigger_error filter; PHP’s own E_DEPRECATED notices are not affected by it.

Check your own site before you upgrade

CompatNav is a free WordPress plugin. It reads the code of your plugins and themes on your own server and tells you, in plain words, what will break and what will only show notices on the PHP version you choose. It never changes your code. It can’t see problems that only appear while code runs with real data, so a quick check of your site after the upgrade still matters.

Get CompatNav on wordpress.org How it works

Sources

About the code examples: each output is the real output of the code shown, run with the official PHP builds, without a php.ini, with all errors reported and displayed. Only the file path was replaced by a neutral server path.