[php]代码库
class a {
public $attr2 = 'a';
private $final_attr = '1';
function __construct() {
$vars = get_class_vars(get_class($this));
foreach($vars as $k => $val) {
if(substr($k,0,strlen('final_')) == 'final_') continue;
$v = 'final_'.$k;
if(isset($this ->$v )) {
echo 'class : ' . get_class($this) . " Can't declare parent's attribute!";
exit();
}
}
}
function __set($attr,$val) {
$v = 'final_'.$attr;
if(isset($this -> $v)) {
$this -> $v = $val;
}
}
function __get($k) {
$v = 'final_'.$k;
if(isset($this -> $v)) {
return $this -> $v;
}
}
}
class b extends a {
public $attr = 'b';
function __construct() {
parent::__construct();
}
}
$a = new b();