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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.