Skip to content

Commit 8b6b235

Browse files
authored
Merge pull request #180 from antecedent/feature/179-callrerouting-fix-php-8.5-deprecation-notice
PHP 8.5 | Prevent some "Using null as an array offset" deprecation notices
2 parents 5f7b015 + e9d4379 commit 8b6b235

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
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, [

src/CodeManipulation/Actions/CallRerouting.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
const CALL_INTERCEPTION_CODE = '
1616
$__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}";
17-
$__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : null;
17+
$__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : "";
1818
if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) {
1919
$__pwCalledClass = $__pwClass ? \get_called_class() : null;
2020
$__pwFrame = \count(\debug_backtrace(0));
@@ -29,7 +29,7 @@
2929

3030
const CALL_INTERCEPTION_CODE_VOID_TYPED = '
3131
$__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}";
32-
$__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : null;
32+
$__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : "";
3333
if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) {
3434
$__pwCalledClass = $__pwClass ? \get_called_class() : null;
3535
$__pwFrame = \count(\debug_backtrace(0));
@@ -47,7 +47,7 @@
4747

4848
const CALL_INTERCEPTION_CODE_NEVER_TYPED = '
4949
$__pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\\\{closure}" : "\\\\{closure}";
50-
$__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : null;
50+
$__pwClass = (__CLASS__ && __FUNCTION__ !== $__pwClosureName) ? __CLASS__ : "";
5151
if (!empty(\Patchwork\CallRerouting\State::$routes[$__pwClass][__FUNCTION__])) {
5252
$__pwCalledClass = $__pwClass ? \get_called_class() : null;
5353
$__pwFrame = \count(\debug_backtrace(0));

0 commit comments

Comments
 (0)