Skip to content

Commit 5f0c012

Browse files
committed
PHP 8.5 | CallRerouting: prevent deprecation notice for Reflection*::setAccessible()
Since PHP 8.1, calling the `Reflection*::setAccessible()` methods is no longer necessary as reflected properties/methods/etc will always be accessible. However, the method calls are still needed for PHP < 8.1. As of PHP 8.5, calling the `Reflection*::setAccessible()` methods is now formally deprecated and will yield a deprecation notice, which will fail test runs. As of PHP 9.0, the `setAccessible()` method(s) will be removed. With the latter in mind, this commit prevents the deprecation notice by making the calls to `setAccessible()` conditional. Silencing the deprecation would mean, this would need to be "fixed" again come PHP 9.0, while the current solution should be stable, including for PHP 9.0. Ref: https://wiki.php.net/rfc/deprecations_php_8_5#extreflection_deprecations
1 parent 4cecc74 commit 5f0c012

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/CallRerouting.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ function relay(?array $args = null)
326326
try {
327327
if (isset($top['class'])) {
328328
$reflection = new \ReflectionMethod(Stack\topCalledClass(), $top['function']);
329-
$reflection->setAccessible(true);
329+
(\PHP_VERSION_ID < 80100) && $reflection->setAccessible(true);
330330
$result = $reflection->invokeArgs(Stack\top('object'), $args);
331331
} else {
332332
$result = call_user_func_array($top['function'], $args);
@@ -518,7 +518,7 @@ function connectDefaultInternals()
518518
}
519519
try {
520520
$reflection = new \ReflectionMethod($class, $method);
521-
$reflection->setAccessible(true);
521+
(\PHP_VERSION_ID < 80100) && $reflection->setAccessible(true);
522522
$args[$offset] = function() use ($reflection, $instance) {
523523
return $reflection->invokeArgs($instance, func_get_args());
524524
};

0 commit comments

Comments
 (0)