Skip to content

Commit

Permalink
[PHP 8.4] E_STRICT deprecation
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Ayesh committed Sep 28, 2024
1 parent 7ad43b6 commit 31e5d94
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
6 changes: 5 additions & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Exception/ErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 13 additions & 11 deletions test/Exception/ErrorExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

/**
Expand Down

0 comments on commit 31e5d94

Please sign in to comment.