Non-static method … should not be called statically

◇◆丶佛笑我妖孽 提交于 2019-11-27 20:05:06
mamdouh alramadan

That means it should be called like:

$timer = (new VTimer)->get($options['magic']);

The difference between static and non-static is that the first one doesn't need initialization so you can call the classname then append :: to it and call the method immediately. Like so:

ClassName::method();

and if the method is not static you need to initialize it like so:

$var = new ClassName();
$var->method();

However, in PHP 5.4 you can use this syntax instead as a shorthand:

(new ClassName)->method();

You can also change the method to be static like so:

class Handler {
    public static function helloWorld() {
        echo "Hello world!";
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!