【备忘录】关于PHP继承
继承是指某人接收和继承先辈的财产、权力或责任的过程。
将在一个类中定义的属性或方法继承到另一个类中。
被继承的类被称为“父类(超类)”,继承的类被称为“子类(子类)”。
继承的方法 de
class 子クラス名 extends 親クラス { }
示例代码
<?php
class Human {
  protected $name;
  // 初期化処理
  public function __construct($name) {
    $this->name = $name;
  }
  //名前を返す
  public function getName() {
    return $this->name;
  }
  // 名前を表示する
  public function introduce() {
    echo $this->getName();
  }
}
  // オブジェクトを生成・初期化
  $human = new Human("tanaka");
  
  // メソッドの実行
  $human->introduce();
  // 継承されたBuchoクラス
  class Bucho extends Human {
  }
  $bucho = new Bucho("sato");
  echo "<br>";
  $bucho->introduce();
以下是执行结果
tanaka
sato