<?php// 重载class Demo{//定义私有 属性private $techer = "杨";private $role = "1";// 属性重载,__get魔术方法,不经过属性直接访问到魔术方法public function __get($name){if ($this->role === "英雄")return $this->techer;elsereturn "非法访问...";}}$obj = new Demo;echo $obj->$techer;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号