<?php
// 重载
class Demo
{
//定义私有 属性
private $techer = "杨";
private $role = "1";
// 属性重载,__get魔术方法,不经过属性直接访问到魔术方法
public function __get($name)
{
if ($this->role === "英雄")
return $this->techer;
else
return "非法访问...";
}
}
$obj = new Demo;
echo $obj->$techer;