Home > other >  PHP return $this;
PHP return $this;

Time:02-10

My question is a simple one. When returning a var_dump of $this I am getting the object and the properties inside. My question in: Shouldn't it return the methods also?

class Test{
    private  $num = 5;
    protected  $dum = 9;

    private function see(){
        return "I see";
    }

    public function returnThis(){
        return var_dump($this);
    }
}

$test = new Test();

$test->returnThis();

Result:

object(Test)#1 (2) {
    ["num":"Test":private]=>
        int(5)
    ["dum":protected]=>
        int(9)
}

CodePudding user response:

  •  Tags:  
  • Related