$this的作用域在PHP中是一个bug还是一个特性


scope of $this is funked in PHP is it a bug or a feature?

我有这样的代码:

    class a(){
      function b(){
         if(isset($this){
            echo 'instance! ';
            echo get_class($this);
         }else{
            echo 'static';
         }
      }
    }

class C{
  public function test(){
      a::b();
  }
}
$CC=new C;
$CC->test();

返回

实例C

伪变量$this在对象上下文中调用方法时可用。$this是对调用对象的引用(通常是该方法所属的对象,但如果从辅助对象的上下文中静态调用该方法,则可能是另一个对象)。

来源

显然,这是一个功能,这是设计的,而不是一个bug。