假设 $this 来自不兼容的上下文,不应静态调用非静态方法 tNG_log::log()
Non-static method tNG_log::log() should not be called statically, assuming $this from incompatible context
我收到上述错误 - 这是它所指的代码:
function executeTransaction() {
tNG_log::log('tNG' . $this->transactionType, 'executeTransaction', 'begin');
if ($this->started) {
tNG_log::log('tNG' . $this->transactionType, 'executeTransaction', 'end');
return false;
}
我不确定如何有效地编辑以上代码以使错误消息消失。我知道我可以编辑 php.ini 文件,这样就不会显示这些错误,但是我宁愿修复代码
class tNG_log() 的方法 log() 未定义为静态函数。
无需从 class 创建对象即可调用静态方法,就像您的示例 class::staticFunction() 一样。
这仅在 class 中有效,代码类似于:
class tNG_log {
public static function log(...) {
// ...
}
}
假设 tNG_log-code 是正确的并且不应被静态调用,解决方案是从 class:
创建一个对象
$tnglog = new tNG_log();
$tnglog->log(...);
如果您想了解更多信息,请从阅读开始http://php.net/manual/en/language.oop5.static.php
我收到上述错误 - 这是它所指的代码:
function executeTransaction() {
tNG_log::log('tNG' . $this->transactionType, 'executeTransaction', 'begin');
if ($this->started) {
tNG_log::log('tNG' . $this->transactionType, 'executeTransaction', 'end');
return false;
}
我不确定如何有效地编辑以上代码以使错误消息消失。我知道我可以编辑 php.ini 文件,这样就不会显示这些错误,但是我宁愿修复代码
class tNG_log() 的方法 log() 未定义为静态函数。 无需从 class 创建对象即可调用静态方法,就像您的示例 class::staticFunction() 一样。 这仅在 class 中有效,代码类似于:
class tNG_log {
public static function log(...) {
// ...
}
}
假设 tNG_log-code 是正确的并且不应被静态调用,解决方案是从 class:
创建一个对象$tnglog = new tNG_log();
$tnglog->log(...);
如果您想了解更多信息,请从阅读开始http://php.net/manual/en/language.oop5.static.php