-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecation of the E_STRICT
constant in PHP 8.4
#5956
Comments
PHPUnit 10 and PHPUnit 11 also use this constant. |
For reference: php/php-src#13053 |
E_STRICT
constant in PHP 8.4
Could it be this simple? diff --git a/src/Runner/ErrorHandler.php b/src/Runner/ErrorHandler.php
index 9e51f98ba..34ff5f0a2 100644
--- a/src/Runner/ErrorHandler.php
+++ b/src/Runner/ErrorHandler.php
@@ -19,7 +19,6 @@
use const E_NOTICE;
use const E_PARSE;
use const E_RECOVERABLE_ERROR;
-use const E_STRICT;
use const E_USER_DEPRECATED;
use const E_USER_ERROR;
use const E_USER_NOTICE;
@@ -27,7 +26,9 @@
use const E_WARNING;
use function array_keys;
use function array_values;
+use function constant;
use function debug_backtrace;
+use function defined;
use function error_reporting;
use function restore_error_handler;
use function set_error_handler;
@@ -90,9 +91,12 @@ public function __invoke(int $errorNumber, string $errorString, string $errorFil
$ignoredByBaseline = $this->ignoredByBaseline($errorFile, $errorLine, $errorString);
$ignoredByTest = $test->metadata()->isIgnoreDeprecations()->isNotEmpty();
+ if (defined('E_STRICT') && $errorNumber === constant('E_STRICT')) {
+ $errorNumber = E_NOTICE;
+ }
+
switch ($errorNumber) {
case E_NOTICE:
- case E_STRICT:
Event\Facade::emitter()->testTriggeredPhpNotice(
$test,
$errorString, As I am currently travelling, I do not have access to a build of PHP 8.4-dev with php/php-src#13053. Therefore I cannot check whether |
@mvorisek Do you have any insight? Thanks! |
I support the patch above but you can also simplify |
That was fast, thank you very much! |
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 noE_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
How to reproduce
Run a test that triggers PHPUnit's error handler.
Expected behavior
No deprecation is triggered.
The text was updated successfully, but these errors were encountered: