php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43277 Interfaces behaving too much like classes
Submitted: 2007-11-13 12:19 UTC Modified: 2007-11-20 19:01 UTC
From: krister dot karlstrom at arcada dot fi Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.5 OS: Linux/Slackware
Private report: No CVE-ID: None
 [2007-11-13 12:19 UTC] krister dot karlstrom at arcada dot fi
Description:
------------
I found this "weird" mix-up of the behaviour of interfaces and abstract classes. I think that you should be able to always implement an interface, regardless of how and where some of the implemented methods where declared or defined. The only thing that should matter is that the declared class defines all the methods that the interface requires.

The error message from PHP says that it can't inherit the method Test::foo() - an implementation of an interface has nothing to do with inheritance in classes in the OO-model. It shouldn't even try to "inherit" the methods of the interface, just check that the defined class implements all of the required methods.

Reproduce code:
---------------
<?php

interface Test
{
	public function foo();
}

abstract class Bar
{
	public abstract function foo();
}

class FooBar extends Bar implements Test 
{
	public function foo()
	{
		echo "Hello!";
	}
}

?>

Expected result:
----------------
I expect this to raise no error, because the class FooBar nicely defines and implements the method foo(), as the interface Test defines.

Actual result:
--------------
[error] PHP Fatal error:  Can't inherit abstract function Test::foo() (previously declared abstract in Bar) in /var/www/asta.arcada.fi/beta/foobar.php on line 13

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-20 19:01 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

PHP is class based OOP, not prototype based. Hence in your example there are two conflicting methods.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 08:01:32 2024 UTC