0

このコードが機能する理由を誰かに説明してもらえますか?

<?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

//UPDATE iParentChild に __construct を追加しました

4

1 に答える 1