__callStatic doesn't handle missing static cal

2019-08-14 08:17发布

class Foo
{
    public function bar(){
        echo "Non-static\n";
    }

    public static function __callStatic($name, $arguments)
    {
        if ($name === 'bar') {
            echo "Static\n";
        }
    }
}

Foo::bar();

Class Foo does not have a static bar method. That is why I was expecting the Foo::bar() to be handled by the __callStatic method. Unfortunately for me that's not happening for some reason.

The non-static method is being called on null instead.

Is it a bug or a feature? How can I make the __callStatic to handle that call of a missing static method?

0条回答
登录 后发表回答