tags:

views:

68

answers:

3

Can you do something like this in PHP:

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

    // do something
}
+6  A: 

use parent;

parent::foo();

Byron Whitlock
`->` will trigger fatal error. Always use `::`. PHP will call parent in same mode (instance/static) as child was called.
webbiedave
yeah, I miswrote that and fixed within 10 seconds ;)
Byron Whitlock
Cool. +1 ––––––
webbiedave
+3  A: 

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
}
notJim
+3  A: 

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