colap Posted February 5, 2011 Share Posted February 5, 2011 If i declare protected variable in a class how can i access those variable in other class inheriting that class? Can anyone post example code? Link to comment https://forums.phpfreaks.com/topic/226746-protected-variable-in-a-php-class/ Share on other sites More sharing options...
trq Posted February 5, 2011 Share Posted February 5, 2011 class a { protected $var = 'foo'; } class b extends a { public function test() { echo $this->var; } } $b = new b; $b->test(); Link to comment https://forums.phpfreaks.com/topic/226746-protected-variable-in-a-php-class/#findComment-1170134 Share on other sites More sharing options...
colap Posted February 5, 2011 Author Share Posted February 5, 2011 Is there anything like in C++ to extend or to inherit a class :public , :protected ? Only extending a class can one access public and protected all members in PHP? Link to comment https://forums.phpfreaks.com/topic/226746-protected-variable-in-a-php-class/#findComment-1170151 Share on other sites More sharing options...
trq Posted February 6, 2011 Share Posted February 6, 2011 Is there anything like in C++ to extend or to inherit a class :public , :protected ? No. Only extending a class can one access public and protected all members in PHP? No, public can be accessed from anywhere. Link to comment https://forums.phpfreaks.com/topic/226746-protected-variable-in-a-php-class/#findComment-1170514 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.