ReflectionMethod::invoke() Deprecates Passing An Object For A Static Method
ReflectionMethod::invoke() and ReflectionMethod::invokeArgs() take an object as the first argument, used as $this for instance methods. Until PHP 8.6, passing an object for a static method was silently accepted and the object was simply ignored. In PHP 8.6, passing a non-null object for a static method emits a deprecation notice, even though the call still succeeds.
PHP code
<?php
class C {
public static function staticMethod() {
return "called";
}
}
$rm = new ReflectionMethod(C::class, 'staticMethod');
var_dump($rm->invoke(new C()));
?>
Before
string(6) "called"
After
PHP Deprecated: Calling ReflectionMethod::invoke() for static method C::staticMethod() does not need an object parameter in /codes/reflectionInvokeStaticObject.php on line 10
Deprecated: Calling ReflectionMethod::invoke() for static method C::staticMethod() does not need an object parameter in /codes/reflectionInvokeStaticObject.php on line 10
string(6) "called"
PHP version change
This behavior was deprecated in 8.6.
This behavior changed in .