我最近对 PHP 5.4 进行了更新,我收到关于静态和非静态代码的错误。
这是错误:
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
这是第 371 行:
$timer = VTimer::get($options['magic']);
我希望有人能帮忙。
原文由 Novice Hobby PHP Boy 发布,翻译遵循 CC BY-SA 4.0 许可协议
这意味着它应该被称为:
$timer = (new VTimer)->get($options['magic']);
The difference between
static
andnon-static
is that the first one doesn’t need instantiation so you can call theclassname
then append::
to它并立即调用该方法。像这样:如果该方法不是静态的,则需要像这样初始化它:
但是,在 PHP >=5.4 中,您可以使用此语法作为简写: