php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45601 Extending interfaces
Submitted: 2008-07-23 11:30 UTC Modified: 2015-04-07 16:59 UTC
Votes:7
Avg. Score:4.1 ± 1.5
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:4 (100.0%)
From: david at grudl dot com Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 5.3CVS-2008-07-23 (snap) OS: irrelevant
Private report: No CVE-ID: None
 [2008-07-23 11:30 UTC] 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) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-23 11:33 UTC] david at grudl dot com
p.s. is really the error message formulation "(previously declared abstract in IHuman)" correct?
 [2011-03-23 00:11 UTC] clicky at erebot dot net
See also bug #46705 for other suggestions on how to improve the way interfaces currently work in PHP.
 [2011-12-04 09:40 UTC] clicky at erebot dot net
This issue and a few others dealing with interfaces have been solved in PHP 5.4RC2 & 5.3.9RC2.
 [2015-04-07 16:59 UTC] nikic@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: nikic
 [2015-04-07 16:59 UTC] nikic@php.net
As clicky mentioned, this is fixed since PHP 5.3.9.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 00:01:34 2025 UTC