Hi,
Code below is just to print a message. Nothing more. Question is: Whether we have the line return $this->myname;
or not, it works fine but why some people still use return
in such cases? Is it just a matter of taste or I'm missing something about OOP? Example below might look silly but I just wanted to explain what I meant.
Thanks in advance
class Whatever
{
var myname = null;
private function set_my_name($name)
{
$this->myname = $name;
return $this->myname;
}
public function say_hello($name)
{
$this->set_my_name($name);
echo 'Hello ' . $this->myname;
}
}
$obj = new Whatever();
$obj->say_hello('John');