<?php
class a{
public function out(){
$this->test = 8;
return $this->test;
}
}
$b = new a();
echo $b->out();
?>
output: 8
when i run this code, output the result 8 .
but when i add __set() function, it output a notice, and not 8 output
<?php
class a{
public function __set($property, $value) {
}
public function out(){
$this->test = 8;
return $this->test;
}
}
$b = new a();
echo $b->out();
?>
output:
PHP Notice: Undefined property: a::$test in /usercode/file.php on line 13
why is it happening?
__setand it doesn't then set the property within the method, then the property won't exist, and will raise a notice when you try and read it.