我试图访问它的子类中的父类属性,但我不断收到此错误致命错误:未定义类常量'臂'blabla.php 26行。 这是我下面的代码blabla.php如何访问扩展类中的父级PHP类属性
blabla.php
<?php
class mother
{
public $legs;
public $arms;
public $eyes;
function say($arm,$eye,$leg)
{
$this->arms = 'pretty';
$this->eyes = 'stunning';
$this->legs = 'beautiful slim';
}
}
class daughter extends mother
{
public $newArms;
public $newEyes;
public $newLegs;
public function newSay()
{
$this->newArms = parent::arms;
$this->newEyes = parent::eyes;
$this->newLegs = parent::legsparent::arms;
echo 'I have a beautiful daughter who has '.$this->newArms.' arms, '.$this->newEyes.' eyes and '.$this->newLegs.' legs';
}
}
$baby = new daughter();
$baby->newSay();
?>
如果在我的代码错误,请告诉我,如何纠正它。 在此先感谢。
您正在犯一个根本性错误。女儿不应该延长母亲。一位母亲有一个女儿,女儿是一个新的实体,不是母亲的延伸。 – vascowhite