谁能解释我为什么这段代码有效?
<?php
class iParent
{
private $device;
private $browser;
public function __construct()
{
$this->device = 'iPad';
$this->browser = 'Safari';
}
public function getDetails()
{
return 'Device ' . $this->device . ' ' . 'Browser ' . $this->browser;
}
}
/**
*
*/
class iParentChild extends iParent
{
public function __construct()
{
echo 'IParentChild constructor';
}
public function display()
{
return $this->getDetails();
}
}
$obj = new iParentChild;
echo $obj->display();
// Output
Device iPad Browser Safari
我认为只有parent::__construct()
在iParentChild
.
//更新我在 iParentChild 中添加了 __construct