类中属性重载技术

Original 2019-07-03 16:42:01 272
abstract:<?php const IS_ISSET = true; const IS_SET = true; const IS_GET = true; const IS_UNSET = false; class Visit{ protected $data&n
<?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;


Correcting teacher:查无此人Correction time:2019-07-04 13:20:05
Teacher's summary:完成的不错。基础上php已经入门了,以后多练习实战项目。继续加油。

Release Notes

Popular Entries