PHP009 継承
継承
・子クラスは親クラスのプロパティ/メソッドを利用可能。
逆に子でユニークなものを親は利用不可。
・instanceofでどこのクラスか判別可。
・コンストラクタをオーバーライドさせる場合、子クラスでは[parent::__construct(...)]とparentを使う。
<?php require_once('human.php'); //Femaleクラス class Female extends Human{ public function __construct($name, $price, $image, $type) { parent::__construct($name,$price,$image); $this->type = $type; } private $type; public function getType(){ return $this->type; } public function setType($type;){ $this->type = $type; } } /* if ($ichigo instanceof Female) { echo $ichi->getName().'はFmaleクラスのインスタンスです'; */ ?>