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? Quote 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(); Quote 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? Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.