Relative Callable In Strings

PHP has a syntax to designate a method, with its class and method name as a string. That syntax used to support relative class names, such as self, parent and static. That allowed the definition of callable that would be relative to their point of execution, and not their point of definition. This is a gone feature in PHP 8.2.

PHP code

<?php

class x {
    function a() {
        print __METHOD__;
    }

    function b() {
        call_user_func('self::a');
    }
}

(new x)->b();

?>

Before

x::a

After

PHP Deprecated:  Use of "self" in callables is deprecated

Deprecated: Use of "self" in callables is deprecated
x::a

PHP version change

This behavior was deprecated in 8.2

This behavior changed in 9.0

See Also

Error Messages

Analyzer