Home >Backend Development >PHP Tutorial >php 魔术方法简述

php 魔术方法简述

WBOY
WBOYOriginal
2016-06-23 13:25:24795browse

```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');```

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn