Scope $ this, called by PHP, is this a bug or function?

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(); 

It will be an echo

instance C

+8
oop php
source share
1 answer

The pseudo-variable $ this is available when the method is called from the context of the object. $ 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 the secondary object).

a source

So definitely, this is a feature, it is by design, and it is not a mistake.

+5
source share

All Articles