From 428c22b42b486db7c3966cecfdd1dc6dec871943 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 9 Feb 2026 05:04:27 -0300 Subject: [PATCH 1/5] Fix Deprecated `ArrayObject::__construct()` and Method `ReflectionMethod::setAccessible()` in PHP `8.5`. --- phpstan-baseline.neon | 128 +----------------------------- src/FlattenException.php | 2 +- src/models/router/RouterRules.php | 6 +- tests/TestCase.php | 12 ++- 4 files changed, 20 insertions(+), 128 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ba371f909..e6ec0a593 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -264,12 +264,6 @@ parameters: count: 1 path: src/Module.php - - - message: '#^Method yii\\debug\\Module\:\:checkAccess\(\) has parameter \$action with generic class yii\\base\\Action but does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/Module.php - - message: '#^Method yii\\debug\\Module\:\:corePanels\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -462,12 +456,6 @@ parameters: count: 1 path: src/actions/db/ExplainAction.php - - - message: '#^Class yii\\debug\\actions\\db\\ExplainAction extends generic class yii\\base\\Action but does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/actions/db/ExplainAction.php - - message: '#^Method yii\\debug\\components\\search\\Filter\:\:addMatcher\(\) has no return type specified\.$#' identifier: missingType.return @@ -552,12 +540,6 @@ parameters: count: 1 path: src/controllers/DefaultController.php - - - message: '#^Class yii\\debug\\controllers\\DefaultController extends generic class yii\\web\\Controller but does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/controllers/DefaultController.php - - message: '#^Method yii\\debug\\controllers\\DefaultController\:\:getManifest\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -624,24 +606,6 @@ parameters: count: 1 path: src/controllers/UserController.php - - - message: '#^Class yii\\debug\\controllers\\UserController extends generic class yii\\web\\Controller but does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/controllers/UserController.php - - - - message: '#^Method yii\\debug\\controllers\\UserController\:\:actionResetIdentity\(\) return type with generic class yii\\web\\User does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/controllers/UserController.php - - - - message: '#^Method yii\\debug\\controllers\\UserController\:\:actionSetIdentity\(\) return type with generic class yii\\web\\User does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/controllers/UserController.php - - message: '#^Parameter \#1 \$identity of method yii\\debug\\models\\UserSwitch\:\:setUserByIdentity\(\) expects yii\\web\\IdentityInterface, yii\\web\\IdentityInterface\|null given\.$#' identifier: argument.type @@ -696,18 +660,6 @@ parameters: count: 1 path: src/models/UserSwitch.php - - - message: '#^Method yii\\debug\\models\\UserSwitch\:\:getMainUser\(\) return type with generic class yii\\web\\User does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/models/UserSwitch.php - - - - message: '#^Method yii\\debug\\models\\UserSwitch\:\:getUser\(\) return type with generic class yii\\web\\User does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/models/UserSwitch.php - - message: '#^Method yii\\debug\\models\\UserSwitch\:\:getUser\(\) should return yii\\web\\User\|null but returns object\|null\.$#' identifier: return.type @@ -726,42 +678,18 @@ parameters: count: 1 path: src/models/UserSwitch.php - - - message: '#^Method yii\\debug\\models\\UserSwitch\:\:setUser\(\) has parameter \$user with generic class yii\\web\\User but does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/models/UserSwitch.php - - message: '#^Method yii\\debug\\models\\UserSwitch\:\:setUserByIdentity\(\) has no return type specified\.$#' identifier: missingType.return count: 1 path: src/models/UserSwitch.php - - - message: '#^Property yii\\debug\\models\\UserSwitch\:\:\$_mainUser with generic class yii\\web\\User does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/models/UserSwitch.php - - message: '#^Property yii\\debug\\models\\UserSwitch\:\:\$_user \(yii\\web\\User\) does not accept object\|null\.$#' identifier: assign.propertyType count: 1 path: src/models/UserSwitch.php - - - message: '#^Property yii\\debug\\models\\UserSwitch\:\:\$_user with generic class yii\\web\\User does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/models/UserSwitch.php - - - - message: '#^Property yii\\debug\\models\\UserSwitch\:\:\$userComponent with generic class yii\\web\\User does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/models/UserSwitch.php - - message: '#^Binary operation "\." between string\|null and array\\|string results in an error\.$#' identifier: binaryOp.invalid @@ -1962,12 +1890,6 @@ parameters: count: 1 path: src/panels/UserPanel.php - - - message: '#^Method yii\\debug\\panels\\UserPanel\:\:getUser\(\) return type with generic class yii\\web\\User does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/panels/UserPanel.php - - message: '#^Method yii\\debug\\panels\\UserPanel\:\:getUser\(\) should return yii\\web\\User\|null but returns object\|null\.$#' identifier: return.type @@ -1986,12 +1908,6 @@ parameters: count: 1 path: src/panels/UserPanel.php - - - message: '#^PHPDoc tag @var for variable \$userController contains generic class yii\\base\\Controller but does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/panels/UserPanel.php - - message: '#^PHPDoc tag @var with type yii\\base\\Controller is not subtype of native type null\.$#' identifier: varTag.nativeType @@ -1999,7 +1915,7 @@ parameters: path: src/panels/UserPanel.php - - message: '#^Parameter \#1 \$action of method yii\\filters\\AccessRule\:\:allows\(\) expects yii\\base\\Action\\>, yii\\base\\Action\\|null given\.$#' + message: '#^Parameter \#1 \$action of method yii\\filters\\AccessRule\:\:allows\(\) expects yii\\base\\Action, yii\\base\\Action\\|null given\.$#' identifier: argument.type count: 1 path: src/panels/UserPanel.php @@ -2040,12 +1956,6 @@ parameters: count: 1 path: src/panels/UserPanel.php - - - message: '#^Property yii\\debug\\panels\\UserPanel\:\:\$userComponent with generic class yii\\web\\User does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: src/panels/UserPanel.php - - message: '#^Result of && is always false\.$#' identifier: booleanAnd.alwaysFalse @@ -2131,7 +2041,7 @@ parameters: path: src/views/default/panels/db/callers.php - - message: '#^Cannot access property \$summary on yii\\console\\Controller\\|yii\\web\\Controller\\|null\.$#' + message: '#^Cannot access property \$summary on yii\\console\\Controller\|yii\\web\\Controller\|null\.$#' identifier: property.nonObject count: 1 path: src/views/default/panels/db/callers.php @@ -2203,7 +2113,7 @@ parameters: path: src/views/default/panels/db/detail.php - - message: '#^Cannot access property \$summary on yii\\console\\Controller\\|yii\\web\\Controller\\|null\.$#' + message: '#^Cannot access property \$summary on yii\\console\\Controller\|yii\\web\\Controller\|null\.$#' identifier: property.nonObject count: 1 path: src/views/default/panels/db/queries.php @@ -2665,7 +2575,7 @@ parameters: path: src/views/layouts/main.php - - message: '#^Cannot access property \$module on yii\\console\\Controller\\|yii\\web\\Controller\\|null\.$#' + message: '#^Cannot access property \$module on yii\\console\\Controller\|yii\\web\\Controller\|null\.$#' identifier: property.nonObject count: 1 path: src/views/layouts/main.php @@ -2862,12 +2772,6 @@ parameters: count: 1 path: tests/router/RouterRulesTest.php - - - message: '#^Class yiiunit\\debug\\router\\controllers\\BadController extends generic class yii\\web\\Controller but does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: tests/router/controllers/BadController.php - - message: '#^Method yiiunit\\debug\\router\\controllers\\BadController\:\:actionOnly\(\) has no return type specified\.$#' identifier: missingType.return @@ -2892,12 +2796,6 @@ parameters: count: 1 path: tests/router/controllers/RedirectController.php - - - message: '#^Class yiiunit\\debug\\router\\controllers\\RedirectController extends generic class yii\\web\\Controller but does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: tests/router/controllers/RedirectController.php - - message: '#^Method yiiunit\\debug\\router\\controllers\\RedirectController\:\:actionOnly\(\) has no return type specified\.$#' identifier: missingType.return @@ -2910,18 +2808,6 @@ parameters: count: 1 path: tests/router/controllers/RedirectController.php - - - message: '#^Class yiiunit\\debug\\router\\controllers\\RestController extends generic class yii\\rest\\ActiveController but does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: tests/router/controllers/RestController.php - - - - message: '#^Class yiiunit\\debug\\router\\controllers\\WebController extends generic class yii\\web\\Controller but does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: tests/router/controllers/WebController.php - - message: '#^Method yiiunit\\debug\\router\\controllers\\WebController\:\:actionFirst\(\) has no return type specified\.$#' identifier: missingType.return @@ -2940,12 +2826,6 @@ parameters: count: 1 path: tests/router/controllers/WebController.php - - - message: '#^Class yiiunit\\debug\\router\\module\\controllers\\ModuleWebController extends generic class yii\\web\\Controller but does not specify its types\: T$#' - identifier: missingType.generics - count: 1 - path: tests/router/module/controllers/ModuleWebController.php - - message: '#^Method yiiunit\\debug\\router\\module\\controllers\\ModuleWebController\:\:actionInside\(\) has no return type specified\.$#' identifier: missingType.return diff --git a/src/FlattenException.php b/src/FlattenException.php index ef3e48392..ec23647c5 100644 --- a/src/FlattenException.php +++ b/src/FlattenException.php @@ -292,7 +292,7 @@ private function flattenArgs($args, $level = 0, &$count = 0) */ private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value) { - $array = new \ArrayObject($value); + $array = new \ArrayObject(\get_object_vars($value)); return $array['__PHP_Incomplete_Class_Name']; } diff --git a/src/models/router/RouterRules.php b/src/models/router/RouterRules.php index a9ffb242c..6dfda671d 100644 --- a/src/models/router/RouterRules.php +++ b/src/models/router/RouterRules.php @@ -143,7 +143,11 @@ protected function scanRestRule($restRule) { $reflectionClass = new \ReflectionClass($restRule); $reflectionProperty = $reflectionClass->getProperty('rules'); - $reflectionProperty->setAccessible(true); + + if (PHP_VERSION_ID < 80500) { + $reflectionProperty->setAccessible(true); + } + $rulesGroups = $reflectionProperty->getValue($restRule); foreach ($rulesGroups as $rules) { diff --git a/tests/TestCase.php b/tests/TestCase.php index f9ba2e69b..2fbb576cf 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -73,9 +73,17 @@ protected function invoke($object, $method, array $args = []) { $classReflection = new \ReflectionClass(get_class($object)); $methodReflection = $classReflection->getMethod($method); - $methodReflection->setAccessible(true); + + if (PHP_VERSION_ID < 80500) { + $methodReflection->setAccessible(true); + } + $result = $methodReflection->invokeArgs($object, $args); - $methodReflection->setAccessible(false); + + if (PHP_VERSION_ID < 80500) { + $methodReflection->setAccessible(false); + } + return $result; } } From 03194830f02b8f914042c9e7bb2a7d3ab3a3a03a Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 9 Feb 2026 05:10:28 -0300 Subject: [PATCH 2/5] Add line to `CHANGELOG.md`. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9280c0a6e..3cd1e0424 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Yii Framework 2 debug extension Change Log - Bug #541: Silence fetch errors (Karkbauer) - Enh #546: Applying Yii2 coding standards (@s1lver) - Enh #546: Raise min version to PHP 7.4 (@s1lver) +- Bug #548: Fix Deprecated ArrayObject::__construct() and Method ReflectionMethod::setAccessible() in PHP 8.5 (@terabytesoftw) 2.1.27 June 08, 2025 From 0b87324c0f04593748700252c01fb771a931a2dd Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 9 Feb 2026 05:12:58 -0300 Subject: [PATCH 3/5] Fix error typo in `CHANGELOG.md`. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cd1e0424..bc4ddabf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ Yii Framework 2 debug extension Change Log - Bug #541: Silence fetch errors (Karkbauer) - Enh #546: Applying Yii2 coding standards (@s1lver) - Enh #546: Raise min version to PHP 7.4 (@s1lver) -- Bug #548: Fix Deprecated ArrayObject::__construct() and Method ReflectionMethod::setAccessible() in PHP 8.5 (@terabytesoftw) +- Bug #548: Fix `Deprecated ArrayObject::__construct()` and Method `ReflectionMethod::setAccessible()` in PHP 8.5 (@terabytesoftw) 2.1.27 June 08, 2025 From 2c9be5a3243f3c5288239ef832f3ff9507adf25a Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 9 Feb 2026 05:20:39 -0300 Subject: [PATCH 4/5] Apply fixed Copilot review. --- src/FlattenException.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FlattenException.php b/src/FlattenException.php index ec23647c5..398acbe7d 100644 --- a/src/FlattenException.php +++ b/src/FlattenException.php @@ -292,8 +292,8 @@ private function flattenArgs($args, $level = 0, &$count = 0) */ private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value) { - $array = new \ArrayObject(\get_object_vars($value)); + $array = \get_object_vars($value); - return $array['__PHP_Incomplete_Class_Name']; + return (string) ($array['__PHP_Incomplete_Class_Name'] ?? ''); } } From 37d0ccaa235beb603c999053414633b2b9d67cc5 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 9 Feb 2026 07:51:45 -0300 Subject: [PATCH 5/5] Apply fixed review. --- src/models/router/RouterRules.php | 2 +- tests/TestCase.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/models/router/RouterRules.php b/src/models/router/RouterRules.php index 6dfda671d..e7359709a 100644 --- a/src/models/router/RouterRules.php +++ b/src/models/router/RouterRules.php @@ -144,7 +144,7 @@ protected function scanRestRule($restRule) $reflectionClass = new \ReflectionClass($restRule); $reflectionProperty = $reflectionClass->getProperty('rules'); - if (PHP_VERSION_ID < 80500) { + if (PHP_VERSION_ID < 80100) { $reflectionProperty->setAccessible(true); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 2fbb576cf..d58d95cfe 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -74,13 +74,13 @@ protected function invoke($object, $method, array $args = []) $classReflection = new \ReflectionClass(get_class($object)); $methodReflection = $classReflection->getMethod($method); - if (PHP_VERSION_ID < 80500) { + if (PHP_VERSION_ID < 80100) { $methodReflection->setAccessible(true); } $result = $methodReflection->invokeArgs($object, $args); - if (PHP_VERSION_ID < 80500) { + if (PHP_VERSION_ID < 80100) { $methodReflection->setAccessible(false); }