Cristiano Duarte wrote:
On Tue, 17 Feb 2004 15:34:11 +0000, Stephane Drouard wrote:
Hans,
In PHP you are not allowed to explicit overload methods. Ex:
class A { function x($a1) {} function x($a1, $a2) {} }
The function "x" is already defined and explicit overloading is not possible, so the code above will result in parser error.
Yes, that I know :) Perhaps I misused the word overloading at some point. Overloading is essentially the feature that I am sorely missing here.
In PHP you are allowed to do overriding. The code you supplied:
class A { function init() { ... } function doSomething($arg1, $arg2) { ... } }
class B extends A { function doSomething($arg1, $arg2, $arg3, $arg4 = null) { ... } function doSomethingElse($arg1) { ... } }
You are redefining the function doSomething at the child and this is "overriding".
But when you use an interface, you are telling PHP that you class has a commitment to implement some functions(signatures).
Since you agreed at the commitment, you can't break it doing overriding(with a different signature - arguments). The only way is overloading, but PHP doesn't support it(you can do overloading with __call, __get and __set but that's not the case).
Ok, I guess that's just how it is in PHP. The only thing I would cling to is that this behavior is inconsistent with the way classes behave: i.e. you can override a method in a class and the ($obj instanceof ParentClass) will return still return true.
I think that overriding with default arguments would get around 90% of the cases where this is a problem. It won't get around my specific case, but I can live with just not using an OO hierarchy for my code.
I still think that interfaces should follow the same behavior as classes (i.e. if you can override in classes you can override in interfaces), but I understand that academically this is wrong. Of course overriding is wrong period, but it's the route you have to take when overloading isn't an option.
Thanks all -
Hans
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php