以下是我想要使用的注册码。但是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());