private 修饰的属性不能被继承和重写,protected可以
class Person
{
private $name = 'KaiNan';
protected $age = 22;
public function getAge() {
echo $this->age,'<br>';
echo $this->name;
}
}
class Stu extends Person
{
private $name = 'NuoKe';
protected $age = 18;
public function intro()
{
parent::getAge();
}
}
$lucy = new Stu();
$lucy->intro();
/*
18
KaiNan
*/