当前位置:Gxlcms > PHP教程 > php魔术方法简述

php魔术方法简述

时间:2021-07-01 10:21:17 帮助过:6人阅读

```name = $name; } public function getName() { return $this->name; } // 针对属性,设置值 public function __set($name, $value) { $this->$name = $value; } // 针对属性,读取值 public function __get($name) { if (isset($this->$name)) { return $this->$name; }else{ echo '尚未设置初始值'; } } // 针对方法,处理方法名和参数 public function __call($name, $arguments) { var_dump($arguments); return $name; } // 针对直接echo 类名的时候,调用__tostring()方法 public function __tostring() { return "this is a function tostring"; }}$student = new person('张三');echo $student; // this is a function tostring$student ->age = '李四';echo $student ->age; // 李四echo $student ->getAge('32');```

人气教程排行