In PHP? It doesn’t really have much advantage, but is changing with the language metamorphosis.
If you’re programming like PHP was designed it doesn’t really make sense because interface is a contract engine where you say what methods a type of having and then you create types that conform to it, and in your code you can say that somewhere accepts an interface and then any object that implements the interface can be used there because it meets its requirement.
It’s a way for you to give a name to an operation that an object can do, and then you can say you accept objects that know how to do the operation. So it’s a mechanism to ensure robustness, give type security.
But PHP is a dynamic typing language, and it makes no sense to ask for type security in such a language. PHP is a language of script and shouldn’t have to deal with this kind of complexity.
It is true that PHP realized that this is not very good and is changing the philosophy, but you can not fix everything for compatibility reasons, so it is a hybrid thing and has the worst of both worlds (part of the best too, of course, but partial does not help so much).
Want type security? Great, use it in a static typing language that forces this to occur in all cases. Like PHP? Use Hack. Otherwise think Java, C#, these things.
Don’t care about security types? Ok, if really what you do is script she is not so necessary, but then it becomes strange to use interface.
If you understand everything you are doing in the code you will see that much of what is preached today in PHP does not make sense. People use it without question. I’m glad you asked.
See more in:
Wonder! Great answer... eh exactly what I think. Hug
– 1001Songs Clips