I just wanted to note the fact that I disagree with this.
In a perfect world, I would go with an E_COMPILE_ERROR in all situations; when inheriting regular classes (w/o abstract methods), abstract methods and interfaces. That is what the academic part of me feels but knows can't be done.
As this would break BC too much, I agree that inheriting from regular classes should not lead to an error. I believe that for consistency sake interfaces and abstract classes should behave the same as regular classes, thus, if regular classes don't cause an error, the former also shouldn't.
I propose to leave things the way they are:
a) In E_STRICT error_reporting there's an E_STRICT warning when overriding a method with an incompatible signature (for all cases).
b) PHP will keep BC compatibility for old classes and consistency between them and the new classes. This way old classes and new classes/interfaces will all behave the same.
That said, if the majority of people prefer the more aggressive approach of E_COMPILE_ERROR with interfaces and abstract methods, it can be changed.
Andi
At 11:49 AM 4/19/2004 +0300, Zeev Suraski wrote:
All,
Yesterday, someone complained that classes that implement interfaces succeed in doing so even when they don't satisfy the prototypes. While this does cause an E_STRICT message to be emitted, it would go unnoticed in most cases, as E_STRICT is off by default, in some cases - even when people think it's on.
I believe that this behavior is wrong. I believe that classes should not be allowed to say they implement an interface X, unless they actually implement all of the methods in that interface with methods that are compatible with its prototypes.
Reasoning:
- Interfaces (and for that matter, abstract classes) are a new feature in PHP 5, used solely to enforce implementing classes to abide to the prototypes. There's no issue of downwards compatibility, and there's no other use case.
- Without this, the whole mechanism of class type hints is rendered useless. With it, it gives users the full power of class type hints (and instanceof, for that matter) - because they always have the option of adding an interface for their base classes.
Suggested behavior:
Any method that implements (directly or indirectly) an interface method or an abstract method, will have implementation checks fully enforced, with an E_COMPILE_ERROR emitted in case of an error.
Behavior for methods that override regular parent methods, that do not have interface/abstract prototypes, will not change (E_STRICT message).
Comments welcome - we'd like to sort this out before RC2...
Zeev
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php