scope of $this is funked in PHP is it a bug or a feature?
I have this code:
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();
This will echo
开发者_开发技巧instance C
The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object).
source
So definitely, it's a feature, it's by design, and it's not a bug.
精彩评论