<?php
namespace _0930;
class demo3
{
private $name = 'xis';
private $salary= 556;
protected $secret = '是不是男的';
public function __construct($name,$salary)
{
$this->name = $name;
$this->salary = $salary;
/*$this->secret = $secret;*/
}
public function __get($pname)
{
if($pname === 'secret')
{
return ($this->name === 'admin') ? $this->$pname : '无权查看';
}
return $this->$pname;
}
/*public function __get($salary)
{
return $tihs->$salary;
}*/
}
$obj = new demo3('admin',6666);
echo $obj->secret;
``
php魔术方法__get()
最新推荐文章于 2022-02-23 11:22:49 发布