开发者

Calling a super method in PHP

开发者 https://www.devze.com 2023-01-17 08:57 出处:网络
Can you do something like this in PHP: functi开发者_如何转开发on foo() { super->foo(); // do something

Can you do something like this in PHP:

functi开发者_如何转开发on foo()
{
    super->foo();

    // do something
}


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
}


use parent;

parent::foo();


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号