diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 5e1986a4056..0229411c9b2 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -13,6 +13,7 @@ Yii Framework 2 Change Log - Enh #20268: Minor optimisation in `\yii\helpers\BaseArrayHelper::map` (chriscpty) - Enh #20273: Remove unnecessary `paragonie/random_compat` dependency (timwolla) - Chg #20276: Removed autogenerated migration phpdoc (userator) +- Bug #20282: Fix compatibility with PHP 8.4: deprecated constant E_STRICT (Izumi-kun) 2.0.51 July 18, 2024 -------------------- diff --git a/framework/base/ErrorException.php b/framework/base/ErrorException.php index f9c388a5453..a5af2a8027a 100644 --- a/framework/base/ErrorException.php +++ b/framework/base/ErrorException.php @@ -124,15 +124,14 @@ public function getName() E_NOTICE => 'PHP Notice', E_PARSE => 'PHP Parse Error', E_RECOVERABLE_ERROR => 'PHP Recoverable Error', - E_STRICT => 'PHP Strict Warning', E_USER_DEPRECATED => 'PHP User Deprecated Warning', E_USER_ERROR => 'PHP User Error', E_USER_NOTICE => 'PHP User Notice', E_USER_WARNING => 'PHP User Warning', E_WARNING => 'PHP Warning', self::E_HHVM_FATAL_ERROR => 'HHVM Fatal Error', - ]; + ] + (PHP_VERSION_ID < 80400 ? [E_STRICT => 'PHP Strict Warning'] : []); - return isset($names[$this->getCode()]) ? $names[$this->getCode()] : 'Error'; + return $names[$this->getCode()] ?? 'Error'; } } diff --git a/tests/framework/base/ErrorExceptionTest.php b/tests/framework/base/ErrorExceptionTest.php index 615b706fa6d..0054136ad7f 100644 --- a/tests/framework/base/ErrorExceptionTest.php +++ b/tests/framework/base/ErrorExceptionTest.php @@ -41,4 +41,13 @@ public function testXdebugTrace() $this->assertEquals(__FUNCTION__, $e->getTrace()[0]['function']); } } + + public function testStrictError() + { + if (!defined('E_STRICT')) { + $this->markTestSkipped('E_STRICT has been removed.'); + } + $e = new ErrorException('', @E_STRICT); + $this->assertEquals(PHP_VERSION_ID < 80400 ? 'PHP Strict Warning' : 'Error', $e->getName()); + } }