面向对象 __isset 魔术方法

来源:互联网 发布:软件产品出口退税政策 编辑:程序博客网 时间:2024/05/20 22:03
<?phpheader("Content-Type: text/html; charset=utf-8");class person{private $name;protected $age;public function __construct($name,$age){$this -> name = $name;$this -> age = $age;}public function is_set($name){return isset($this -> $name);}/* * 魔术方法__isset 自动调用 * 在类的外部用函数is_set判断私有的、受保护的成员属性时被自动调用 * 参数:判断的成员属性名 * 作用:可以按需求去返回false和true */public function __isset($name){if($name == 'age'){return false;}return isset($this -> $name);}}$person = new person('精灵',20);echo $person -> is_set('name');echo $person -> is_set('age');//var_dump($person -> is_set('name'));//原始方法//var_dump($person -> is_set('age'));//原始方法?>

原创粉丝点击