我有一个关于在PHP中扩展类的问题。
我在php官网上看到的例子只有方法中的1行代码...如果方法有很多代码,是不是一样的呢?
如果这是基类:
class BaseClass {
public function WithWayTooMuchCode {
// like 100 lines of code here
}
}
如果我想使用同样的方法,但只改变 1 或 2 个东西,那么我是否需要复制所有代码呢?
class MyOwnClass extends BaseClass {
public function WithWayTooMuchCode {
// like 100 lines of code here
// do I have to copy all of the other code and then add my code??
}
}
这对我来说似乎不太符合DRY原则...
parent::methodName()
即可访问父类功能。 - user895378parent::methodName()
是无济于事的。 - Johannes Klauß