我有这个抽象类抽象类的构造函数中重写混淆
abstract class Guitar {
protected $strings;
public function __construct($no_of_strings) {
$this->strings = $no_of_strings;
echo 'Guitar class constructor is called <br/>';
}
abstract function play();
}
而子类,
class Box_Guitar extends Guitar {
public function __construct($no_of_strings) {
echo 'Box Guitar constructor is called <br/>';
$this->strings = $strings + 100;
}
public function play() {
echo 'strumming ' . $this->strings;
}
}
然后,我开始与阶级,
$box_guitar = new Box_Guitar(6);
而且我出来放了
箱吉他构造函数被调用
吉他类构造函数被调用
拨弄106
所以我的问题是,为什么父类的构造被称为?我没有使用Parent :: __ construct()。
让我检查......... – Namal
+1代码先测试:) – 2013-07-14 08:17:40
我加了一个答案.... – Namal