Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

php - Non-static method ..... should not be called statically

I have recently done an update to PHP 5.4, and I get an error about static and non-static code.

This is the error:

PHP Strict Standards:  Non-static method VTimer::get() 
should not be called statically in /home/jaco/public_html/include/function_smarty.php on line 371

This is the line 371:

$timer  = VTimer::get($options['magic']);

I hope somebody can help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...