Use of “static” in callables is deprecated

Description

Since PHP 8.2, it is not possible anymore to use static as a string, when creating a callable. static 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('static','foo'));
    }
}

X::test();

?>

Solutions

  • Use static::class to make this class name non-ambiguous.

  • Use another way to create a closure for the method, such as static::foo(...).

See Also