Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

php - Cannot implement two interfaces that have the same method name

This doesn't work:

interface TestInterface
{
    public function testMethod();
}

interface TestInterface2
{
    public function testMethod();
}

class TestClass implements TestInterface, TestInterface2
{

}

Gives me the error:

Fatal error: Can't inherit abstract function TestInterface2::testMethod() (previously declared abstract in TestInterface).

Is that correct? 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 that has an abstract function of the same name.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It appears that current PHP versions actually can do this. I've tracked the change in behavior down to this commit:

https://github.com/php/php-src/commit/31ef559712dae57046b6377f07634ad57f9d88cf#Zend/zend_compile.c

So as of php-5.3.9 the documented behavior appears to have changed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...