Edit report at https://bugs.php.net/bug.php?id=45601&edit=1
ID: 45601
Comment by: clicky at erebot dot net
Reported by: david at grudl dot com
Summary: Extending interfaces
Status: Open
Type: Feature/Change Request
Package: Feature/Change Request
Operating System: irrelevant
PHP Version: 5.3CVS-2008-07-23 (snap)
Block user comment: N
Private report: N
New Comment:
This issue and a few others dealing with interfaces have been solved in PHP
5.4RC2 & 5.3.9RC2.
Previous Comments:
------------------------------------------------------------------------
[2011-03-23 00:11:36] clicky at erebot dot net
See also bug #46705 for other suggestions on how to improve the way interfaces
currently work in PHP.
------------------------------------------------------------------------
[2008-07-23 11:33:10] david at grudl dot com
p.s. is really the error message formulation "(previously declared abstract in
IHuman)" correct?
------------------------------------------------------------------------
[2008-07-23 11:30:28] david at grudl dot com
Description:
------------
I think this fatal error is needless.
Interface implementors can append optional parameter:
interface IAnimal
{
function speak();
}
class Dog implements IAnimal
{
function speak($optional = NULL)
{
echo 'Bark!';
}
}
class Labrador extends Dog
{
function speak($optional = NULL, $anotherOptinal = NULL)
{
...
}
}
That's correct behaviour. But the same behaviour is unallowed for interface
extenders.
Reproduce code:
---------------
interface IAnimal
{
function speak();
}
interface IHuman extends IAnimal
{
function speak($language = NULL);
}
Expected result:
----------------
no error
Actual result:
--------------
Fatal error: Can't inherit abstract function IAnimal::speak() (previously
declared abstract in IHuman)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=45601&edit=1