美文网首页PHP
静态函数Using $this when not in obje

静态函数Using $this when not in obje

作者: 一名鼻炎患者 | 来源:发表于2018-10-10 18:41 被阅读0次

静态函数能不实例化就可以调用,使用self::方法(),但是在调用静态函数时需注意,静态函数后续调用函数,只能用self而不能用$this

    /**
     * 例如
     */
class TestController extends \Think\Controller{
    public function t1(){
        $this->t2();
    }
    private static  function t2(){
        self::t3();
    }
    private function t3(){
        $this->t4();//这个地方就会报错 Using $this when not in object context,修改成为self::t4();就可以了
    }
    private function t4(){
        die("sss");
    }
}

相关文章

网友评论

    本文标题:静态函数Using $this when not in obje

    本文链接:https://www.haomeiwen.com/subject/xyfajxtx.html