Animal类
class Animal {
private $kind ;
function __construct($kind) {
$this -> kind = $kind;
}
function wow() {
echo $this -> kind;
}
}
Cat类
class Cat extends Animal {
function __construct() {
parent::__construct("Cat");
}
function mow() {
echo "mow!";
}
}
test.php
$cat = new Cat();
$cat -> wow();
$cat -> mow();
可以看出php继承使用的也是extends 关键字
php中调用父类的构造方法不是使用super关键字 , 而是使用parent::__construct(参数1 , 参数2 , 参数3)的形式来调用。