<?php class Person { private $name; private $age; public function __get($property_name) { echo "自动调用__get()方法获取属性值<br>"; if(isset($this->$property_name)) { return($this->$property_name); } else { return (NULL); } } public function __set($property_name,$value) { echo "自动调用__set()方法获取属性值<br>"; $this->$property_name = $value; } } $p = new Person(); $p->name = "张三"; echo $p->name."你真是个傻逼啊你!!!"; ?>