Do you know what% username% is?
If yes, then I think this code will not cause you questions. PHP subtleties (strangeness?) Work with interfaces
interface someInterface{ public function someMethod(); } interface anotherInterface{ public function someMethod(); } class Foo implements someInterface,anotherInterface { public function someMethod(){ echo 'someMethod() was called'.PHP_EOL; } } $foo = new Foo(); $foo->someMethod();
So that will display the script as a result of their work.
The answer is under katom.

The correct answer is: “Fatal error: Can not inherit abstract function ...” But why? - quite rightly ask you. The same question I asked and when I first encountered this. As the search showed, this is a fad, dignity, disadvantage, stupidity, advantage (underline the necessary) PHP. If we take a look at the
php.net/manual/en/language.oop5.interfaces.php tutorial in which they write such scary things: “Note: A class can’t make ambiguity.” In other words, The PHP class cannot implement several interfaces containing the same methods, as this creates ambiguity. Stop, stop, stop ... Let's see. Let's recall multiple inheritance in C ++.
class someClass { public: void someMethod(){ }; } class anotherClass { public: void someMethod(){ }; } class fooClass: someClass,anotherClass{ } int main () { fooClass foo; foo.someMethod(); return 0; }

This is where the uncertainty is present, since it is unclear which method will be inherited (well, almost). Interfaces were invented just to resolve the collision arising from the multiple inheritance of classes. After all, to put it bluntly, the interface is only a “set of instructions”, which says that the class implementing it must implement such methods. The interface does not contain the implementation of the method, so this class is “all the same” if it has to implement many interfaces with the same methods. Again, this is just an “instruction” telling the class that it should implement this method, just a few of these instructions. The logic of PHP developers is not entirely clear, why did we again get a piece that does not work like everywhere else? Why a class cannot implement interfaces with the same methods? Why does this lead to ambiguity?
UPD1: for some reason, the second person in the comments speaks about the overloading of the
en.wikipedia.org/wiki/Method_overloading methods (the same method name, but different call signatures: different types of parameters passed to the method, their number, etc. ...). I guess I didn’t explain something wrong, but the article doesn’t talk about overloadin. PHP does not really support this mechanism. But in this case, the multiple implementation of interfaces, this mechanism is not relevant.
Once again in PHP, a class cannot implement several interfaces containing the same methods, in Java / C # / etc it is possible:
public interface someInterface { public void someMethod(); } public interface anotherInterface { public void someMethod(); } public class fooClass implements anotherInterface,someInterface { public static void main(String[] args) { fooClass fooClass = new fooClass(); fooClass.someMethod(); } @Override public void someMethod() { System.out.println("someMethod() was called"); } }
UPD: 2 solution of the same problem on C #
habrahabr.ru/blogs/php/116916/#comment_3808966UPD: 3 checked the same code in D
en.wikipedia.org/wiki/D_%28programming_language%29, it seems like a new OOP language, the ed file is working properly:
import std.stdio; import std.stream; interface D{ void foo(); } interface A{ void foo(); } class E : D, A{ void foo(){ writefln("foo() was called"); } } void main (string[] args){ E e = new E(); e.foo(); } alagar@home:~/d$ dmd -run ed foo() was called