Calling a super method in PHP

PhpOop

Php Problem Overview


Can you do something like this in PHP:

function foo()
{
	super->foo();
	
	// do something
}

Php Solutions


Solution 1 - Php

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
}

Solution 2 - Php

use parent;

parent::foo();

Solution 3 - Php

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();
  }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEmanuil RusevView Question on Stackoverflow
Solution 1 - PhpdavidtbernalView Answer on Stackoverflow
Solution 2 - PhpByron WhitlockView Answer on Stackoverflow
Solution 3 - PhpHarold1983-View Answer on Stackoverflow