prezident Posted December 24, 2010 Share Posted December 24, 2010 ini_set('display_errors', 1); error_reporting(E_ALL); class A { private function operation1() //only be used inside this class { echo 'operation1 called'; } protected function operation2() //only inside this class { echo 'operation2 called'; } public function operation3() //public can be used in any class { echo 'operation3 called'; } } class B extends A { function _construct() { //$this->operation1(); //$this ->operation2(); $this->operation3(); } } $b = new B; can someone please tell me why this code doesn't work ? Link to comment https://forums.phpfreaks.com/topic/222564-classes-help/ Share on other sites More sharing options...
requinix Posted December 24, 2010 Share Posted December 24, 2010 The name of the constructor is __construct. There are two underscores. On a side note, protected function operation2() //only inside this class Not quite. Protected members are accessible to the class and its child classes. So B could call $this->operation2 (but not operation1). Link to comment https://forums.phpfreaks.com/topic/222564-classes-help/#findComment-1151036 Share on other sites More sharing options...
prezident Posted December 24, 2010 Author Share Posted December 24, 2010 The name of the constructor is __construct. There are two underscores. On a side note, protected function operation2() //only inside this class Not quite. Protected members are accessible to the class and its child classes. So B could call $this->operation2 (but not operation1). thank you I'm going in to edit now Link to comment https://forums.phpfreaks.com/topic/222564-classes-help/#findComment-1151039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.