Use of “self” in callables is deprecated¶
Description¶
Since PHP 8.2, it is not possible anymore to use self
as a string, when creating a callable. self
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('self','foo'));
}
}
X::test();
?>
Solutions¶
Use
self::class
to make this class name non-ambiguous.Use another way to create a closure for the method, such as
self::foo(...)
.