【发布时间】:2011-01-29 10:36:23
【问题描述】:
我到处都有以下代码:
class Container extends Object implements \IteratorAggregate {
public function AddObject(Object $object, $instanceKey) {
...
}
public function AddComponent(Component $component) {
...
}
}
class MenuContainer extends Container {
public function AddComponent(Menu $component) { // <-- I'm redeclaring the method only because I need to change the typehint
return parent::AddComponent($component);// I don't do anything useful here
}
public function AddObject(Menu $object, $instanceKey) { // <-- I'm redeclaring the method only because I need to change the typehint
return parent::AddObject($object, $instanceKey); // I don't do anything useful here
}
}
我不得不通过方法重新声明来进行 typehint 特化,因为我想防止使用我的代码的人犯错误并意外地在我的菜单中添加一些不兼容的内容。那么问题来了:有没有一种方法可以在没有实际方法重新声明的情况下进行 typehint 特化?
【问题讨论】:
标签: php