Non-static method ..... should not be called statically(非静态方法 ..... 不应静态调用)
问题描述
我最近更新了 PHP 5.4,但收到关于静态和非静态代码的错误.
I have recently done an update to PHP 5.4, and I get an error about static and non-static code.
这是错误:
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']);
希望有人能帮忙.
推荐答案
这意味着它应该被称为:
That means it should be called like:
$timer = (new VTimer)->get($options['magic']);
static 和 non-static 的区别在于第一个不需要初始化,所以你可以调用 classname 然后追加:: 并立即调用该方法.像这样:
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();
但是,在 PHP 5.4 中,您可以使用以下语法作为简写:
However, in PHP 5.4 you can use this syntax instead as a shorthand:
(new ClassName)->method();
                        这篇关于非静态方法 ..... 不应静态调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:非静态方法 ..... 不应静态调用
				
        
 
            
        - openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
 - PHP foreach() 与数组中的数组? 2022-01-01
 - 如何在 Symfony2 中正确使用 webSockets 2021-01-01
 - Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
 - 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
 - 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
 - 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
 - PHP - if 语句中的倒序 2021-01-01
 - Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
 - 覆盖 Magento 社区模块控制器的问题 2022-01-01
 
