Eric_Ryk Posted December 14, 2006 Share Posted December 14, 2006 I have a parent class that looks like this:[code]abstract class P_Part{ private $parts; public function __construct() { $this -> parts = array(); } public function get_parts() { return $parts; }}[/code]And a child class that looks like this:[code]class C_Part extends P_Part{ public function __construct() { parent::__construct(); } public function asdf() { $this -> parts[] = 5; $this -> parts[] = 6; }}[/code]Then I do something like the following:[code]$c_part = new C_Part();$c_part -> asdf();var_dump($c_part -> get_parts());[/code]I get an empty array. Link to comment https://forums.phpfreaks.com/topic/30690-inheritance-issue/ Share on other sites More sharing options...
448191 Posted December 14, 2006 Share Posted December 14, 2006 Duh. It's because the parents' $parts is private. It's not the same $parts, as the parents' $parts is unavailable to the childs $parts. Link to comment https://forums.phpfreaks.com/topic/30690-inheritance-issue/#findComment-141412 Share on other sites More sharing options...
Eric_Ryk Posted December 14, 2006 Author Share Posted December 14, 2006 [quote author=448191 link=topic=118659.msg485091#msg485091 date=1166134806]Duh. It's because the parents' $parts is private. It's not the same $parts, as the parents' $parts is unavailable to the childs $parts.[/quote]Gah, thanks for some reason I'm still in the habit of private instead of protected. Link to comment https://forums.phpfreaks.com/topic/30690-inheritance-issue/#findComment-141413 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.