PHP 8.4: E_STRICT constant deprecated

Version8.4
TypeDeprecation

All of the errors, warnings, and notices in PHP have an error level assigned to them, and using the error_reporting and set_error_handler functions, PHP applications can control which errors are reported and override the default error-handling behavior with a custom callback.

PHP has a wide range of error levels, with the E_ALL constant being the bit-mask OR of all the E_ constants, which means the setting error reporting or the error handler to report/handle all errors, warnings, and notices.

One of the error levels PHP previously emitted was E_STRICT, on code that was not "strictly" correct to ensure interoperability and forward compatibility. PHP 7.0 converted the majority of existing E_STRICT warnings to E_NOTICE, and since PHP 8.0, all E_STRICT notices have changed to E_NOTICE.

Because all of the E_STRICT notices are upgraded to E_NOTICE since PHP 8.0, PHP 8.5 deprecates the E_STRICT constant.


error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
Constant E_STRICT is deprecated

Suggested Replacement

PHP core and core extensions since PHP 8.0 and later do not emit E_STRICT notices at all. It is safe to assume that any PHP applications that run on PHP 8.0 and later will never encounter E_STRICT notices, and error reporting and handling can be safely updated to ignore E_STRICT notices.

- error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
+ error_reporting(E_ALL & ~E_DEPRECATED);

On PHP 7 series before PHP 7.4, the following functions conditionally emit E_STRICT notices:

PHP applications that must support PHP 7.3 or older versions can conditionally call the error_reporting and set_error_handler functions with appropriate error levels:

- error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
+ if (PHP_VERSION_ID >= 70400) {
+   error_reporting(E_ALL & ~E_DEPRECATED);
+ }
+ else {
+   error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
+ }

E_ALL constant value change

The assigned value of the E_ALL constant has changed from 32767 to 30719 in PHP 8.4.

Backward Compatibility Impact

The E_STRICT constant is deprecated in PHP 8.4. Using the constant anywhere in PHP code now emits a deprecation notice in PHP 8.4 and later.

The E_STRICT constant will be removed in PHP 9.0.

Custom error handlers and error reporting controls that selectively exclude E_STRICT notices can adjust them to ignore E_STRICT notices to avoid the deprecation notice.

Custom and PECL extensions emitting E_STRICT notices

It is theoretically possible for PECL and custom PHP extensions to emit E_STRICT notices. However, this is unlikely because majority of PECL extensions have moved to E_NOTICE.


E_STRICT RFC Discussion Implementation