From 9e8db9d3f5fda652a54696dee682289945f5b824 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 15 Sep 2025 19:02:47 +0200 Subject: [PATCH 1/3] PHP 8.5 | Prevent some "Using null as an array offset" deprecation notices These are only some "low hanging fruit" fixes. There is a deeper problem in the underlying wiring causing a lot more of these deprecation notices, which I haven't been able to track down yet. At least the fixes in this PR should allow to focus on the deeper problem by getting rid of a sizable amount of deprecation notices. Ref: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_using_values_null_as_an_array_offset_and_when_calling_array_key_exists --- src/CallRerouting.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/CallRerouting.php b/src/CallRerouting.php index 60b9679..c1fbff9 100644 --- a/src/CallRerouting.php +++ b/src/CallRerouting.php @@ -181,7 +181,7 @@ function inPreprocessedFile($callable) function connectFunction($function, callable $target, ?Handle $handle = null) { $handle = $handle ?: new Handle; - $routes = &State::$routes[null][$function]; + $routes = &State::$routes[''][$function]; $offset = Utils\append($routes, [$target, $handle]); $handle->addReference($routes[$offset]); return $handle; @@ -311,6 +311,10 @@ function dispatch($class, $calledClass, $method, $frame, &$result, ?array $args function relay(?array $args = null) { list($class, $method, $offset) = end(State::$routeStack); + $class = $class ?? ''; + $method = $method ?? ''; + $offset = $offset ?? ''; + $route = &State::$routes[$class][$method][$offset]; $backup = $route; $route = ['Patchwork\fallBack', new Handle]; @@ -387,6 +391,9 @@ function getHHVMExpirationHandler($function) function getRoutesFor($class, $method) { + $class = $class ?? ''; + $method = $method ?? ''; + if (!isset(State::$routes[$class][$method])) { return []; } @@ -431,7 +438,7 @@ function createStubsForInternals() '$__pwRefOffset = 0;', '$__pwRefOffset = 1;', \Patchwork\CodeManipulation\Actions\CallRerouting\CALL_INTERCEPTION_CODE - ), + ), $refs ); eval(strtr(INTERNAL_STUB_CODE, [ From 7e9400ebb78fefd23961fd061c5e73ac95fd12a9 Mon Sep 17 00:00:00 2001 From: Ignas Rudaitis Date: Tue, 16 Sep 2025 13:11:43 +0300 Subject: [PATCH 2/3] Avoid null offsets when performing lookups from CALL_INTERCEPTION_CODE* --- src/CodeManipulation/Actions/CallRerouting.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CodeManipulation/Actions/CallRerouting.php b/src/CodeManipulation/Actions/CallRerouting.php index e5059c3..b0a87c2 100644 --- a/src/CodeManipulation/Actions/CallRerouting.php +++ b/src/CodeManipulation/Actions/CallRerouting.php @@ -14,7 +14,7 @@ const CALL_INTERCEPTION_CODE = ' $__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}"; - $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : null; + $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ''; if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) { $__pwCalledClass = $__pwClass ? \get_called_class() : null; $__pwFrame = \count(\debug_backtrace(0)); @@ -29,7 +29,7 @@ const CALL_INTERCEPTION_CODE_VOID_TYPED = ' $__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}"; - $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : null; + $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ''; if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) { $__pwCalledClass = $__pwClass ? \get_called_class() : null; $__pwFrame = \count(\debug_backtrace(0)); @@ -47,7 +47,7 @@ const CALL_INTERCEPTION_CODE_NEVER_TYPED = ' $__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}"; - $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : null; + $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ''; if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) { $__pwCalledClass = $__pwClass ? \get_called_class() : null; $__pwFrame = \count(\debug_backtrace(0)); From e9d43799695d4532f3430ceb83b1c106e5a1cb58 Mon Sep 17 00:00:00 2001 From: Ignas Rudaitis Date: Tue, 16 Sep 2025 13:15:09 +0300 Subject: [PATCH 3/3] Fix syntax error from prior (hasty) commit --- src/CodeManipulation/Actions/CallRerouting.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CodeManipulation/Actions/CallRerouting.php b/src/CodeManipulation/Actions/CallRerouting.php index b0a87c2..f876ddc 100644 --- a/src/CodeManipulation/Actions/CallRerouting.php +++ b/src/CodeManipulation/Actions/CallRerouting.php @@ -14,7 +14,7 @@ const CALL_INTERCEPTION_CODE = ' $__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}"; - $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ''; + $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ""; if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) { $__pwCalledClass = $__pwClass ? \get_called_class() : null; $__pwFrame = \count(\debug_backtrace(0)); @@ -29,7 +29,7 @@ const CALL_INTERCEPTION_CODE_VOID_TYPED = ' $__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}"; - $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ''; + $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ""; if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) { $__pwCalledClass = $__pwClass ? \get_called_class() : null; $__pwFrame = \count(\debug_backtrace(0)); @@ -47,7 +47,7 @@ const CALL_INTERCEPTION_CODE_NEVER_TYPED = ' $__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}"; - $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ''; + $__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : ""; if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) { $__pwCalledClass = $__pwClass ? \get_called_class() : null; $__pwFrame = \count(\debug_backtrace(0));