For a start, you've written attribure
, not attribute
. When you evaluate $a->attribure = 5;
, __set
gets called with a name of attribure
and a value of 5
, and tries to set $this->attribure to 5. And the class doesn't have an attribute named attribure
. Starting in PHP 8.2 you'd get a deprecation notice about this, but either way your $a
object now has a new property named attribure
with a value of 5.
class classname {
private $attribute;
function __get($name){
return $this->$name;
}
function __set($name,$value){
$this->$name = $value;
}
}
$a = new classname();
/*$a->__get("albert");
//$a->__set("albert",38);
//$a->attribute("albert",38);*/
$a->attribure = 5;
echo $a->attribure;