It is not possible to implement two interfaces that have the same method name

This does not work:

interface TestInterface
{
    public function testMethod();
}

interface TestInterface2
{
    public function testMethod();
}

class TestClass implements TestInterface, TestInterface2
{

}

Gives me an error:

Fatal error: Cannot inherit the abstract function TestInterface2 :: testMethod () (previously declared abstraction in TestInterface).

It is right? Why is this not allowed? Doesn't make sense to me.

This also happens with abstract functions, for example, if you implement an interface and then inherit from a class with an abstract function with the same name.

+5
source share
5 answers

It makes no sense to implement two interfaces containing methods with the same signatures.

, - , , .

:

interface IProgram { function execute($what); /* executes the given program */ }
interface ISQLQuery { function execute($what); /* executes the given sql query */ }

class PureAwesomeness implements IProgram, ISQLQuery {
    public function execute($what) { /* execute something.. but what?! */ }
}

, , - , .

+8

PHP :

PHP 5.3.9 , , . PHP , .

+7
interface BaseInterface
{
    public function testMethod();
}

interface TestInterface extends BaseInterface
{
}

interface TestInterface2 extends BaseInterface
{
}

class TestClass implements TestInterface, TestInterface2
{
    public function testMethod()
    {
    }
}
+3

, PHP , , . , , .

.

-1

All Articles