PHP already has the Object-Oriented function, but why is it so important that the interface function similar to Java is gone? PHP already has the Object-Oriented function, but why is it so important that the interface function similar to Java is gone? Reply: correct use of PHP interface Interfaces
PHP: object interface
What are you taking about? PHP has an interface. When you see something new, you can install it in your own features. Finally, it looks like a static language.
I personally think that the interface is too restrictive and not suitable for dynamic languages. Dynamic Language is more suitable for the concept of a "weak interface", that is, when a method is implemented, it is deemed that an interface is implemented. Anyway, when you call a dynamic language method, it is equivalent to reflection. If you do all reflection, you can use method_exists.
To determine. What are the interfaces required for dynamic languages? First, why. PHP has traits. This was in 2014, and the interface may have been eliminated.
There are also interfaces... There are interfaces and trait, and the method code can be reused directly, without every class being implemented. That is, java uses the interface default method in java 8 to implement things.
In php, it is mainly used for type hinting during runtime.
However, this type hinting can only use clss or interface, but cannot use int or string, which is simply a dynamic language ), when we see the tall ones, we can squeeze them into the language. If we do not do well, we can leave a hole and try again.
First, There is an Interface!
SecondPHP interfaces are not completely useless. Dynamic Language is indeed weak in the use of some object-oriented features, but PHP is reflected in type detection, for example, the usage in the previously viewed Laravel framework is as follows:
public function validateCredentials(UserInterface $user, array $credentials){ ... }