下面是代码:如何访问子类中的基本属性?
<? php
class Animal
{
public $type = 'Animal';
function printProperties()
{
echo $this->type;
}
}
class Dog extends Animal
{
public $type = 'Dog';
function printProperties()
{
echo $this->type.'<br>';
parent::printProperties();
}
$aDog = new Dog;
$aDog-> printProperties();
?>
代码打印Dog newl Dog
我预计输出为Dog newline Animal
。如何得到这个结果。如果覆盖属性,我不能访问achild类中的基本属性吗?
这是不可读的 – Jah
你在第二类中覆盖'$ type',所以'Dog
Dog'是预期的。 – Rasclatt
因此,如果我覆盖父属性,没有办法访问子类中的基本属性? – user5241471