Re: more on interface inheritance issues
| From: | Stephane Drouard | Date: | Tue, 17 Feb 2004 15:34:11 +0000 |
| Subject: | Re: more on interface inheritance issues | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-7925@lists.php.net to get a copy of this message | ||
== Quote from Hans Lellelid (hans@appliedsec.com)'s article
> In more traditional PHP this works fine:
>
> class A {
> function init() { ... }
> function doSomething($arg1, $arg2) { ... }
> }
>
> class B extends A {
> function doSomething($arg1, $arg2, $arg3, $arg4 = null) { ... }
> function doSomethingElse($arg1) { ... }
> }
Even if PHP allows it, there is however a problem.
Imagine you write code that assumes to have a A object. So you call doSomething() with only 2
arguments.
If you now pass to this code a B object, you will have an error because $arg3 is not provided.
So adding arguments to an overloaded method should only be done if the additionnal arguments have a
default value.
Stephane