我创建了一个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)中的$属性替换了(2)中的$属性。但是我已经用new来创建一个新的BasicDiv对象,是不是(1)和(2)彼此独立?