這裏是我的代碼:兒童影響類的父類
class Parent1
{
static $db = null;
public function __construct()
{
self::$db = 'a';
}
}
class Child extends Parent1
{
public function __construct()
{
parent::__construct();
self::$db = 'b';
}
}
$myParent = new Parent1();
echo $myParent::$db; //"a"
$myChild = new Child();
echo $myChild::$db; //"b"
echo $myParent::$db; //"b" it should be "a"
爲什麼$myParent::$db
正在改變b
?如何防止它?