PHP:如果具有不同的值,如何从子类访问受保护的变量?

How can a protected variable be accessed from a child Class if it has a different value?

Example to wrong access: parent::$_my gives error

class Father{
  protected $_my=array('a','b');
}

class Child{
   protected $_my=array('c','d');
  function __construct(){
   parent::__construct();
   $this->_my=array_merge(parent::$_my,$this->_my);
  }
}

Thanks, Yosef

$this->_my will be inherited from the parent when you instantiate a subclass, so you simply need to use:

$this->_my = array_merge($this->_my, array('c','d'));

There is something wrong with you design. You have already declared a variable that can be accessed by child inside parent.

Try adding values to already existing variable, rather than redefining it.