php 的简单存在 (魔术方法作用之一:容错)
来源:互联网 发布:淘宝一对一口语 编辑:程序博客网 时间:2024/09/21 09:04
<span style="font-family:KaiTi_GB2312;font-size:18px;"><?php // 重载class Person{ //定义属性 public $name; private $age; //构造方法 public function __construct($name,$age){ $this->name =$name; $this->age =$age; } //获取魔术方法 # @param string $name public function __get($param){ // return $this->$param; #允许被访问的属性 $allow = array('age'); if(in_array($param, $allow)){ return $this->$param; } } //__set() 设置魔术方法 #@param string $name #param string $val public function __set($name,$val){ $allow = array('age','money'); if(in_array($name, $allow)){ $this->$name=$val; } } // __isset() 判定数据 public function __isset($name){ return isset($this->$name); } //__unset 销毁数据 public function __unset($name){ //建立unset列表 $allow =array('tail'); if(in_array($name,$allow)){ echo 'unset running'; unset($this->$name); } }}//实例化$p = new Person('zp',21);$p->age = 200;echo $p->money = 200000000;$p->tail ="a";var_dump(isset($p->name));var_dump(isset($p->age));var_dump(isset($money));// var_dump(empty($tail));unset($p->tail);// var_dump($tail);</span>
0 0
- php 的简单存在 (魔术方法作用之一:容错)
- php 魔术方法__toString()的作用实例
- PHP 魔术方法及作用
- php -- 魔术方法、魔术常量 简单介绍
- php的魔术方法
- php的魔术方法
- php的魔术方法
- PHP的魔术方法
- PHP的魔术方法
- PHP的魔术方法
- php的魔术方法
- php的魔术方法
- PHP的魔术方法
- PHP的魔术方法
- PHP的魔术方法
- PHP的魔术变量及魔术方法
- PHP的魔术常量和魔术方法
- php魔术方法的使用(总结)
- 二维码生成使用规则
- 成功的自动化测试项目实施
- Xcode 6系列百度网盘地址,包含Xcode 6.2以及Xcode 6.3
- 社説 20150325 辺野古移設作業 冷静さを欠く知事の停止指示
- selenium对flex程序的自动化测试
- php 的简单存在 (魔术方法作用之一:容错)
- 团队管理工具
- Android开发学习笔记:Service的简介和启动方式
- 软件测试的前途
- (priority_queue)优先队列之hihiCoder 第28周
- 一种简单实用的全屏方法
- 【黑马程序员】-核心语法
- 今天的开源项目,用WPF来实现GIF图片的预览和分离和保存
- Spring的IOC原理[通俗解释一下] ---转