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 ? Quote Link to comment 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). Quote Link to comment 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 Quote Link to comment 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.