When a::out()executed, the object does not have a property $test. That is why it $this->test = 8;causesa::__set() .
But it a::__set()does not create a property $test, and the next statement ( return $this->test;) cannot find it and issues a notification.
You must declare the properties of the object in the class definition and initialize them in the constructor (if necessary):
class a {
private $test;
public function __set($property, $value) {
}
public function out() {
$this->test = 8;
return $this->test;
}
}
__set() $this->test = 8; $test , ( ), 8 .
__set() , , ( a private, , protected private ) __set(). __set() $this->test = 8; no-op.