PHP 5.3: Late static binding doesn't work for properties when defined in parent class while missing in child class

后端 未结 1 773
清酒与你
清酒与你 2020-12-09 20:21

Take a look at this example, and notice the outputs indicated.



        
相关标签:
1条回答
  • 2020-12-09 20:42

    It does refer to the correct class, it's just that, unless redeclared or otherwise the reference set is broken, static properties in subclasses are in the same reference set as in the superclass.

    So you must do:

    class Brother extends Mommy
    {
        protected static $_data;
    }
    

    or:

    class Brother extends Mommy
    {
    }
    
    $tmp = null;
    Brother::$_data =& $tmp;
    unset($tmp);
    
    0 讨论(0)
提交回复
热议问题