This is the accessor function:
<?php
class classname
{
public $attribute;
function __get($name)
{
return $this->$name;
}
}
$a = new classname;
$a->attribute = "Anna";
$name = $a->attribute;
echo $name;
?>
And this is just a regular class without accessor functions:
<?php
class classname
{
public $attribute;
}
$a = new classname;
$a->attribute = "Anna";
$name = $a->attribute;
echo $name;
?>
Both of them provide the same result. I don't get it, in what case should I use accessor functions?