From 31e5d947bcf2dcaf36738bd1d8efaeaabddabfa6 Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne Date: Sat, 28 Sep 2024 23:29:43 +0700 Subject: [PATCH] [PHP 8.4] `E_STRICT` deprecation PHP 8.4 deprecates the `E_STRICT` constant because there are no more PHP functions that emit `E_STRICT` warnings/notices. This changes all uses of `E_STRICT` to happen only on PHP 8.3 and older versions. - [RFC: Deprecations for PHP 8.4](https://wiki.php.net/rfc/deprecations_php_8_4) - [`E_STRICT` constant deprecated](https://php.watch/versions/8.4/E_STRICT-deprecated) - [`E_STRICT` codex](https://php.watch/codex/E_STRICT) --- src/Configuration.php | 6 +++++- src/Exception/ErrorException.php | 8 ++++---- src/Shell.php | 5 ++++- test/Exception/ErrorExceptionTest.php | 24 +++++++++++++----------- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/Configuration.php b/src/Configuration.php index 35cc8627..cea81060 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -1023,7 +1023,11 @@ public function useUnicode(): bool */ public function setErrorLoggingLevel($errorLoggingLevel) { - $this->errorLoggingLevel = (\E_ALL | \E_STRICT) & $errorLoggingLevel; + if (\PHP_VERSION_ID < 80400) { + $this->errorLoggingLevel = (\E_ALL | \E_STRICT) & $errorLoggingLevel; + } else { + $this->errorLoggingLevel = \E_ALL & $errorLoggingLevel; + } } /** diff --git a/src/Exception/ErrorException.php b/src/Exception/ErrorException.php index ef3f3570..2600735d 100644 --- a/src/Exception/ErrorException.php +++ b/src/Exception/ErrorException.php @@ -37,10 +37,6 @@ public function __construct($message = '', $code = 0, $severity = 1, $filename = } switch ($severity) { - case \E_STRICT: - $type = 'Strict error'; - break; - case \E_NOTICE: case \E_USER_NOTICE: $type = 'Notice'; @@ -63,6 +59,10 @@ public function __construct($message = '', $code = 0, $severity = 1, $filename = break; default: + if (\PHP_VERSION_ID < 80400 && $severity === \E_STRICT) { + $type = 'Strict error'; + break; + } $type = 'Error'; break; } diff --git a/src/Shell.php b/src/Shell.php index 3cc89c70..192d4c72 100644 --- a/src/Shell.php +++ b/src/Shell.php @@ -1302,10 +1302,13 @@ protected function getSeverity(\ErrorException $e): string case \E_USER_NOTICE: case \E_USER_DEPRECATED: case \E_DEPRECATED: - case \E_STRICT: return 'warning'; default: + if ((\PHP_VERSION_ID < 80400) && $severity === \E_STRICT) { + return 'warning'; + } + return 'error'; } } else { diff --git a/test/Exception/ErrorExceptionTest.php b/test/Exception/ErrorExceptionTest.php index 97ac7e6a..454fccb4 100644 --- a/test/Exception/ErrorExceptionTest.php +++ b/test/Exception/ErrorExceptionTest.php @@ -59,17 +59,19 @@ public function testThrowException($level, $type) public function getLevels() { - return [ - [\E_WARNING, 'Warning'], - [\E_CORE_WARNING, 'Warning'], - [\E_COMPILE_WARNING, 'Warning'], - [\E_USER_WARNING, 'Warning'], - [\E_STRICT, 'Strict error'], - [\E_DEPRECATED, 'Deprecated'], - [\E_USER_DEPRECATED, 'Deprecated'], - [\E_RECOVERABLE_ERROR, 'Recoverable fatal error'], - [0, 'Error'], - ]; + yield [\E_WARNING, 'Warning']; + yield [\E_CORE_WARNING, 'Warning']; + yield [\E_COMPILE_WARNING, 'Warning']; + yield [\E_USER_WARNING, 'Warning']; + + if (\PHP_VERSION_ID < 80400) { + yield [\E_STRICT, 'Strict error']; + } + + yield [\E_DEPRECATED, 'Deprecated']; + yield [\E_USER_DEPRECATED, 'Deprecated']; + yield [\E_RECOVERABLE_ERROR, 'Recoverable fatal error']; + yield [0, 'Error']; } /**