Home » Php » Calling a super method in PHP

Calling a super method in PHP

Posted by: admin November 29, 2017 Leave a comment

Questions:

Can you do something like this in PHP:

function foo()
{
    super->foo();

    // do something
}
Answers:

Yes, it’s called parent:: though.

public function foo()
{
    parent::foo(); // this is not a static method call, even though it looks like one

    //do something
}

Questions:
Answers:

use parent;

parent::foo();

Questions:
Answers:

Do you mean calling the parent class method? In that case you would do:

class Bar
{
  public function foo()
  {
    // blah
  }
}


class Baz extends Bar
{
  public function foo() 
  {
    parent::foo();
  }
}