Jump to content

classes help


prezident

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.