Why is there no interface similar to Java in PHP?

Source: Internet
Author: User
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){ ... }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.