0

这是我想使用的注册表代码。但static不能正常工作。在此示例中,它始终返回 2(而预期为 1)。会是什么?

<?php

class CommonRegistry{

    protected static $register;

    public static function show()
    {
        return static::$register;
    }



}

class NewRegister extends CommonRegistry{

    public function __construct($num)
    {
        static::$register = $num;
    }


}

class AnotherRegister extends CommonRegistry
{

    public function __construct($num)
    {
        static::$register = $num;
    }

}


$a = new NewRegister(1);
$b = new AnotherRegister(2);

var_dump(NewRegister::show());
4

0 回答 0