静态函数Using $this when not in object context

静态函数能不实例化就可以调用,使用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 object context)