类中属性重载技术
至诚网络2019-07-03 16:42:01277 <?php
const IS_ISSET = true;
const IS_SET = true;
const IS_GET = true;
const IS_UNSET = false;
class Visit{
protected $data = [];
public function __isset($name){
return IS_ISSET && isset($this->data[$name]);
}
public function __get($name){
return IS_GET ? $this->data[$name] : '非法访问';
}
public function __set($name,$value){
IS_SET ? $this->data[$name] = $value : '禁止赋值';
}
public function __unset($name){
if(IS_UNSET){
unset($this->data[$name]);
}else{
echo '禁止销毁';
}
}
}
$visit = new Visit();
if(isset($visit->table)){
echo $visit->table,'<br>';
}else{
$visit->table = 'table_staff';
}
echo $visit->table,'<br>';
$visit->table = 'table_foots';
echo $visit->table;
unset($visit->table);
echo $visit->table;