Home>Article>Backend Development> PHP interface technology examples and detailed explanations with pictures and texts

PHP interface technology examples and detailed explanations with pictures and texts

墨辰丷
墨辰丷 Original
2018-05-29 17:23:26 1959browse

This article mainly introduces the PHP interface technology, and analyzes the basic concepts, functions, definitions, usage methods and related precautions of the PHP interface in the form of examples. Friends in need can refer to it

The details are as follows:

1. Interface is a special abstract class. Why do you say that? If all the methods in an abstract class are abstract methods, then we call it an "interface".

2. In addition, variables cannot be declared in the interface.

3. All members in the interface have public permissions. All subclasses must also use public permissions when implementing them.

4. When declaring a class, we use the keyword "class", and when declaring an interface, we use the keyword "interface".

5. Because all methods in the interface are abstract methods, there is no need to use the "abstract" keyword when declaring abstract methods like abstract classes. , this keyword has been added by default.

6. The access permission in the interface must be public. The default is public. "private" and "protected" permissions cannot be used.

7. The interface is a special abstract class. All methods in it are abstract methods, so the interface cannot produce instance objects.

8. We can use the "extends" keyword to let one interface inherit another interface.

interface Two extends One{ function fun3(); function fun4(); }

9. When we define a subclass of an interface to implement all the abstract methods in the interface, the keyword used is "implements", not what we said before "extends".

class Three implements Two{ function fun1() { ; } function fun2() { ; } function fun3(){ ; } function fun4() { ; } } $three = new Three(); $three->fun1();

10.PHP is single inheritance. A class can only have one parent class, but a class can implement multiple interfaces, which is equivalent to one class. There are multiple specifications to follow. To use implements to implement multiple interfaces, all methods in the interface must be implemented before the object can be instantiated.

11.PHP can not only implement multiple interfaces, but also implement multiple interfaces while inheriting a class. You must first inherit the class and then implement the interface.


      

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

php-fpm.conf Configuration Instructions

PHPRealizing multi-process and multi-threading

##PHPSome basic tags to learn

The above is the detailed content of PHP interface technology examples and detailed explanations with pictures and texts. 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