```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');```
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号