类成员访问限制

原创 2018-11-23 10:45:09 231
摘要:class Staff {     public $name;//可以在类的内部、外部、继承子类中使用     protected $dept;//仅在累的内部、继承子类中使用     private $salary;//仅在类内部使用
class Staff
{
    public $name;//可以在类的内部、外部、继承子类中使用
    protected $dept;//仅在累的内部、继承子类中使用
    private $salary;//仅在类内部使用

    public function __construct($name,$dept,$salary)
    {
        $this->name = $name;
        $this->dept = $dept;
        $this->salary = $salary;
    }
    public function getDept(){
        $res = $this->dept;
        if($this->name == '张晓') $res = '保密';
        return $res;
    }
    public function getSalary(){
        $res = $this->salary;
        if($this->name == '张三') $res = '保密保密';
        return $res;
    }
}

$staff = new Staff('张三','销售部',8000);
echo 'name:',$staff->name,'<br>';
echo 'dept:',$staff->getDept(),'<br>';
echo 'salary:',$staff->getSalary(),'<br>';


批改老师:韦小宝批改时间:2018-11-23 10:53:50
老师总结:在实际的开发中权限是很重要的东西哦!这点一定要好好的多多的练习练习哦!继续加油吧!

发布手记

热门词条