Skip to content

Deprecation of the E_STRICT constant in PHP 8.4 #5956

@derrabus

Description

@derrabus
Q A
PHPUnit version 9.6.20, but the 8.5 branch seems to be affected too.
PHP version 8.4-dev
Installation Method Composer

Summary

PHP 8.4 triggers a deprecation if we access the E_STRICT constant.

https://wiki.php.net/rfc/deprecations_php_8_4#remove_e_strict_error_level_and_deprecate_e_strict_constant

That error code is obsolete since PHP 7.0, but some core extensions did still use it in rare cases until PHP 7.4. The deprecation prepares a possible future removal of said constant.

The constant is used inside a switch block that triggers different behavior depending on the error level. This means that even if no E_STRICT errors are triggered, we get a deprecation notice because PHPUnit accesses a deprecated constant for comparison.

I'd volunteer to work on a fix, but I'm not sure about the way forward. Not handling the E_STRICT level at all feels wrong because as long as the level exists, some custom PHP extension could still trigger it. We could just use the plain value of the constant for comparison, assuming that the constant's value will never be changed or repurposed in future PHP releases.

Current behavior

PHP Deprecated:  Constant E_STRICT is deprecated in /path/to/phpunit/src/Util/ErrorHandler.php on line 99

How to reproduce

Run a test that triggers PHPUnit's error handler.

Expected behavior

No deprecation is triggered.

Metadata

Metadata

Labels

type/change-in-php-requires-adaptationA change in PHP requires a change so that existing PHPUnit functionality continues to workversion/10Something affects PHPUnit 10version/11Something affects PHPUnit 11version/8Something affects PHPUnit 8version/9Something affects PHPUnit 9

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions