【发布时间】:2013-05-04 09:13:06
【问题描述】:
我尝试使用父类的名称,例如构造函数,并且部分为我工作。
第一次调用
“DarthVader 方法”
类似于构造函数,但从不调用
“LukeSkywalker 构造函数”..
有人知道怎么做吗?
示例:
达斯.php
class DarthVader{
public function DarthVader(){
echo "-- Obi-Wan never told you what happened to your father.\n";
}
public function reponse(){
echo "-- No. I am your father\n";
}
}
卢克.php
include("Darth.php")
class LukeSkywalker extends DarthVader{
public function __constructor(){
echo "- He told me enough! He told me you killed him!\n"
$this->response();
}
}
预期结果:
欧比旺从未告诉过你父亲的遭遇。
他告诉我的已经够多了!他告诉我你杀了他!
没有。我是你爸爸
我真的很想这样,自动。
【问题讨论】:
-
嘿现在 - 剧透! :D
-
我找到了“卢克天行者构造函数”没有运行的原因。简单地。是“__constructor”,而不是“__constructor”,这支持@Marc B 的理论。谢谢大家
标签: php oop inheritance constructor parent-child