Use of “parent” in callables is deprecated¶
Description¶
Since PHP 8.2, it is not possible anymore to use parent
as a string, when creating a callable. parent
is a keyword with contextual meaning. Then, it has little meaning as a string and leads to confusion.
Example¶
<?php
class X {
static function foo() {
echo __METHOD__;
}
static function test() {
call_user_func(array('parent','foo'));
}
}
X::test();
?>
Solutions¶
Use
parent::class
to make this class name non-ambiguous.Use another way to create a closure for the method, such as
parent::foo(...)
.