From 5f0c012a4f4ccd1973d2cbd2bfcc6ae121bdd5a4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 10 Aug 2025 05:29:36 +0200 Subject: [PATCH] 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 --- src/CallRerouting.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CallRerouting.php b/src/CallRerouting.php index ae8a882..60b9679 100644 --- a/src/CallRerouting.php +++ b/src/CallRerouting.php @@ -326,7 +326,7 @@ function relay(?array $args = null) try { if (isset($top['class'])) { $reflection = new \ReflectionMethod(Stack\topCalledClass(), $top['function']); - $reflection->setAccessible(true); + (\PHP_VERSION_ID < 80100) && $reflection->setAccessible(true); $result = $reflection->invokeArgs(Stack\top('object'), $args); } else { $result = call_user_func_array($top['function'], $args); @@ -518,7 +518,7 @@ function connectDefaultInternals() } try { $reflection = new \ReflectionMethod($class, $method); - $reflection->setAccessible(true); + (\PHP_VERSION_ID < 80100) && $reflection->setAccessible(true); $args[$offset] = function() use ($reflection, $instance) { return $reflection->invokeArgs($instance, func_get_args()); };