如何使用构造函数[php]覆盖子类中父类中声明的属性。
前:
class A {
public $user;
public function __construct {
$this->user = 5;
}
}
class B extends A {
public function __construct {
//How do I make sure that the variables from the parent object are inherited?
}
}
答案 0 :(得分:0)
覆盖父母的构造函数
parent::__construct(); //add this in the child's construct() function
父类和子类的__construct()
语法都需要括号
public function __construct() {
}