Home >Backend Development >PHP Problem >Why can't php instantiate the interface?

Why can't php instantiate the interface?

Guanhui
GuanhuiOriginal
2020-05-07 15:42:423356browse

Why can't php instantiate the interface?

Why can't PHP instantiate the interface?

Interface interface is a rule and is used for implementations, so it cannot be instantiated directly. If you want to To instantiate, other classes need to implement it, and all methods defined by the interface must be implemented before instantiation can be carried out.

Interface interface introduction

Interface is a keyword for interface operations in object-oriented programming languages. Its function is to combine required members to encapsulate certain functions. gather. It is like a template in which the members that an object must implement are defined, through a class or structure. The interface cannot be instantiated directly, that is, ICount ic=new iCount() is wrong. The interface cannot contain any code for the members, only the members themselves are defined. The specific code for interface members is provided by the class that implements the interface. Interfaces are declared using the interface keyword.

The above is the detailed content of Why can't php instantiate the interface?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn