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
$this means the current object, the one the method is currently being run on. By returning $this a reference to the object the method is working gets sent back to the calling function.
PHP $ and $$ Variables. The $var (single dollar) is a normal variable with the name var that stores any value like string, integer, float, etc. The $$var (double dollar) is a reference variable that stores the value of the $variable inside it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With