且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

致命错误:不在对象上下文中使用 $this

更新时间:2023-11-15 08:32:10

$this 只在方法中有意义,在函数中没有意义

$this only makes sense in methods, not in functions

没关系

class Foo {
     function bar() {
          $this->...

这不是

function some() {
    $this->

//没有注意到他将$this"作为参数传递

// edit: didn't notice he passes "$this" as parameter

建议:只需将$this"替换为$somethingElse"

advice: simply replace "$this" with "$somethingElse"