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();
这篇关于非静态方法 ..... 不应静态调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:非静态方法 ..... 不应静态调用
基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
