我创建了一个 HTML 元素构造函数
class ElementConstructor{
protected $properties=array();
function __construct($properties = array(),$tag=''){
if($tag!=''){
$this->element = $tag;
}
if(sizeof($this->properties)>0){
$this->properties = array_merge($this->properties,$properties);
}else{
$this->properties = $properties;
}
}
function init(){
$this->setAttr();
}
function setAttr($attr = NULL){
foreach($this->properties as $name=>$value){
if($name != 'display')
$this->doc[$this->element]->attr($name,$value);
}
}
}
和用途是创建一些基本类包括 Div
class BasicDiv extends ElementConstructor{
protected $element = 'div';
}
之后,我需要使用它
class BasicWrapper extends BasicDiv{
//one (1)
protected $properties = array(
'class'=>'row-fluid sortable ui-sortable',
'id'=>'wrapper'
);
....
function __construct($config=array(),$properties = array()){
parent::__construct($properties);
//(2), the properties replaced by (1)
$secondLevelWrapper = new BasicDiv(array('id'=>'second_level','class'=>'box span12'));
$secondLevelWrapper->init();
}
}
但是,输出显示有两个 DIV 显示,我预计会是 (1): id:wrapper, class:row-fluid sortable ui-sortable 和 (2) id:second_level,class:box span12,但是两个 (1 ) 反而。当我删除 id:wrapper 时,第二个的 id 变得正确。很明显,(1) 中的 $properties 替换了 (2) 中的 $properties。但是我已经用new新建了一个BasicDiv对象,那(1)和(2)不是相互独立的吗?