object - PHP protected and private properties? -
i have class in php upon instance being created takes instance of argument. mock of class below.
abstract class aaa { protected $_a; protected $_b; public function __construct($a, $b) { $this->_a = $a; $this->_b = $b; } } class bbb extends aaa { private $_aaa; public function __construct($a, $b, aaa $aaa) { parent::__construct($a, $b); $this->_aaa = $aaa; } } within method of bbb have full access protected properties of $aaa. example of below.
# bbb method public function getaaaprotected() { return array( '_a' => $this->_aaa->_a, '_b' => $this->_aaa->_b, ); } i confused how can be. understanding of protected properties can accessed extended classes within instance or have been wrong of time.
could please explain, or give direction, can understand when or not protected/private method/function that?
objects of same type have access each others private , protected members though not same instances. because implementation specific details known when inside objects.
http://php.net/manual/en/language.oop5.visibility.php#language.oop5.visibility-other-objects
Comments
Post a Comment