我意识到我将您的界面从公共变量更改为方法,但它可能适合您.请注意,如果允许父操作继续合并,则添加一个天真的setOps($ops)方法可能会出现意外情况.
class A
{
private $ops = array('display'=>false, 'name'=>'John');
public function getops() { return $this->ops; }
}
class B extends A
{
private $ops = array('name'=>'Mathew');
public function getops() { return array_merge(parent::getOps(), $this->ops); }
}
class c extends B
{
private $ops = array('c'=>'c');
public function getops() { return array_merge(parent::getOps(), $this->ops); }
}
$c = new C();
print_r($c->getops());
出:
Array
(
[display] =>
[name] => Mathew
[c] => c
)