关于 __call 的理解

来源:互联网 发布:明解c语言第三版电子版 编辑:程序博客网 时间:2024/06/06 02:05
<?phpclass person{public $name;public $age;public $sex;public $arr = array("aa","bb","cc","dd");function __construct($name,$age,$sex){$this->name = $name;$this->age = $age;$this->sex = $sex;}function say(){echo "我的名字是:{$this->name},我的年龄是:{$this->age},我的性别是:{$this->sex}.<br>";}function __toString(){return "toString<br>";}function __destruct(){echo "析构<br>";}function __clone(){$this->name = "克隆的";}function __call($method,$args){//带有两个参数,第一个是调用的的不在的方法的方法名,第二个是调用这个不存在的方法的方法参数if( in_array($method,$this->arr) ){echo $args[0]."<br>";}else{echo "你调用的方法{$mothod}()不存在";}}}$p = new person("张山",10,"男");$p->aa("aaa");$p->bb("bbb");?>

0 0