Skip to content

Commit 493dc7b

Browse files
committed
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
1 parent 5f7b015 commit 493dc7b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/CallRerouting.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function inPreprocessedFile($callable)
181181
function connectFunction($function, callable $target, ?Handle $handle = null)
182182
{
183183
$handle = $handle ?: new Handle;
184-
$routes = &State::$routes[null][$function];
184+
$routes = &State::$routes[''][$function];
185185
$offset = Utils\append($routes, [$target, $handle]);
186186
$handle->addReference($routes[$offset]);
187187
return $handle;
@@ -311,6 +311,10 @@ function dispatch($class, $calledClass, $method, $frame, &$result, ?array $args
311311
function relay(?array $args = null)
312312
{
313313
list($class, $method, $offset) = end(State::$routeStack);
314+
$class = $class ?? '';
315+
$method = $method ?? '';
316+
$offset = $offset ?? '';
317+
314318
$route = &State::$routes[$class][$method][$offset];
315319
$backup = $route;
316320
$route = ['Patchwork\fallBack', new Handle];
@@ -387,6 +391,9 @@ function getHHVMExpirationHandler($function)
387391

388392
function getRoutesFor($class, $method)
389393
{
394+
$class = $class ?? '';
395+
$method = $method ?? '';
396+
390397
if (!isset(State::$routes[$class][$method])) {
391398
return [];
392399
}
@@ -431,7 +438,7 @@ function createStubsForInternals()
431438
'$__pwRefOffset = 0;',
432439
'$__pwRefOffset = 1;',
433440
\Patchwork\CodeManipulation\Actions\CallRerouting\CALL_INTERCEPTION_CODE
434-
),
441+
),
435442
$refs
436443
);
437444
eval(strtr(INTERNAL_STUB_CODE, [

tests/arguments.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ Patchwork\replace("setArrayElement", function(array &$array, $key, $value) {
1616

1717
$array = [0, 1, "foo" => 2, 3];
1818

19+
var_dump(debug_backtrace());
1920
setArrayElement($array, "foo", "bar");
2021

21-
assert($array == [0, 1, "foo" => "bar", 3]);
22+
var_dump(debug_backtrace());
23+
assert($array === [0, 1, "foo" => "bar", 3]);
2224

2325
?>
2426
===DONE===

0 commit comments

Comments
 (0)