What is the use of $this keyword? Output for both cases are same then why should we need to use $this keyword. And where $this keyword is used .
<?php
class Test
{
private $var;
public function func1()
{
$this->var = 1;
return $this->var;
}
public function func2()
{
$var = 2;
return $var;
}
}
$obj = new Test();
echo $obj->func1();
echo $obj ->func2();
?>
Output for both cases 12 and 12.