__get is not called if __set is not called, however code works?
问题 Here is my code: <?php class SampleClass { public function __get($name){ echo "get called"; echo $name; } public function __set($name, $value) { echo "set called"; } } ?> And my index file: $object = new SampleClass(); $object->color = "black"; echo $object->color; If I run this code as it is, here is the output: set calledget calledcolor However if I comment out public function __set($name, $value) { echo "set called"; } the part above (only this part), then the output will be: black So what