#29417 [Com]: Type hints do not allow for extended interfaces
| From: | matt at builtfromsource dot com | Date: | Fri, 13 Jan 2006 01:02:53 +0000 |
| Subject: | #29417 [Com]: Type hints do not allow for extended interfaces | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-91817@lists.php.net to get a copy of this message | ||
ID: 29417
Comment by: matt at builtfromsource dot com
Reported By: ah08010-zend at yahoo dot com
Status: Suspended
Bug Type: Feature/Change Request
Operating System: *
PHP Version: 5.0.0
Assigned To: hellz
New Comment:
Well, I just ran into this problem as well. Looks like it's been
around for awhile. Any fix on the horizon?
Previous Comments:
------------------------------------------------------------------------
[2004-07-28 05:58:12] helly@php.net
Wow it seems you'd be the first person answering my OOP test question
correctly. Anyway structer is the wrong word here but you are right.
The code you have here should work. If you wanna experiment with that
you can try this patch:
http://marcus-boerger.de/php/ext/ze2/ze2-type-hint-classes-20040719.diff.txt
But though it works in CLI this is not even a proof of concept.
------------------------------------------------------------------------
[2004-07-28 03:41:39] ah08010-zend at yahoo dot com
Description:
------------
Type hints in a derived class
that specify a function parameter
implements an interface
derived from the interface
specified in the (other) interface
implemented by the base class
(whew!)
are flagged as an error despite being type-compatible:
Fatal error: Declaration of TranslatedPlural::compose() must be
compatible with that of Translatable::compose() in
...\TranslatedMessage.php on line 83
Reproduce code:
---------------
// Parameter type hint (BASE)
interface TranslationMap
{
public function fetch($the_key);
}
// Parameter type hint (DERIVED)
interface TranslationLexicon
extends TranslationMap
{
public function plural($the_noun, $the_count);
}
// Implementation Interface
interface Translatable
{
function set_args();
function compose(TranslationMap $map);
}
// Base class
class TranslatedMessage
implements Translatable
{
public function set_args()
{
}
public function compose(TranslationMap $lex)
{
}
}
// Derived class
class TranslatedPlural
extends TranslatedMessage
{
public function compose(TranslationLexicon $lex)
{
}
}
Expected result:
----------------
I expect that the derived class, TranslatedPlural, will be checked for
a stricter (but type-compatible) interface than the base class.
Actual result:
--------------
Fatal error: Declaration of TranslatedPlural::compose() must be
compatible with that of Translatable::compose() in
...\TranslatedMessage.php on line 83
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29417&edit=1