Is there a way to have PHP subclasses inherit properties (both static and instance)?

前端 未结 2 2037
予麋鹿
予麋鹿 2021-01-19 08:26

If I declare a base class as follows:

abstract class Parent {

  protected static $message = \"UNTOUCHED\";

     public static function yeah() {
         st         


        
2条回答
  •  别那么骄傲
    2021-01-19 08:45

    Inheritance and static properties does sometime lead to "strange" things in PHP.

    You should have a look at Late Static Bindings in the PHP's manual : it explains what can happen when inheriting and using static properties in PHP <= 5.2 ; and gives a solutions for PHP >= 5.3 where you can use the static:: keywords instead of self::, so that static binding is done at execution (and not compile) time.

提交回复
热议问题