Call parent static method in php

2020-03-08 09:00发布

问题:

I have a base class A:

class A {
   public static function a() {
      ...
   }
   public static function b() {
      ...
   }
}

and an extended class B

class B extends A {
   public static function a() {
      ...
   }
   public static function c() {
      ...
   }
}

I would like to be able to call all the methods using B:: How would I call A::b, using B::?

回答1:

You should be able to accomplish this as easily as:

class B extends A {
   public static function a() {
      parent::a();
   }
}

See the docs