【发布时间】:2014-01-31 17:32:49
【问题描述】:
假设我有一堂课
class Item {
public function __construct($id) {
if(!empty($id)) {
$this->doSomethingWithID($id);
}
}
public function dummyMethod() {
//does Something.
}
protected function doSomethingWithID($id) {
//Does something with the ID
}
}
如果我有这样的继承类:
class Product extends Item {
public function __construct() {
parent::__construct();
}
protected function doSomethingWithID($id) {
//OVERRIDES THE PARENT FUNCTION
}
}
Product 类会使用被覆盖的 Method 吗?还是会使用 Parent 方法?
【问题讨论】:
-
你可以试试看
-
没办法,因为我正在处理别人的代码并且没有找到安全的测试方法,只是想确保它按照我的想法工作,以便我可以继续分析它。谢谢
标签: php inheritance constructor