Like most object-oriented programming languages, PHP does not support multiple inheritance. This means that each class can inherit only one parent class .
Interface It is the problem of solving that each class can inherit only one parent class.
What permissions the interface uses, and what permissions are used by the inherited method.
The declaration of the interface is used: interface
Interface inheritance using: Implements
Catalogue ++++++++++++++++++++++++++++++++++++++++++++
Declaration of the 00X1 interface and reference to the interface (case i)
00x2 how to inherit multiple interfaces (case two)
00X3 determine if an object implements an interface (case three)
++++++++++++++++++++++++++++++++++++++++++++++
00x1 Case One
<?PHPInterfaceicaneat{#使用interface声明一个接口 Publicfunction Eat ($food);//interface does not require the implementation of a method}classHuman implements icaneat{#使用implements继承接口 (cannot use extends), the properties or methods that will be docked to the interface later are consistent. Publicfunction Eat ($food) {#如该行所示, to be consistent with the properties or methods of the interface. Echo"I eating". $food."\ n"; Once you have implemented an interface, you must provide a concrete implementation of the methods defined in the interface. }23} $test=NewHuman (); $test->eat ('Apple'); ?>
The output effect is as follows:
I eating apple
00x2 Case Two
The inheritance of multiple interfaces can be achieved by separating them with commas after implments.
Format:
Implements interface 1, interface 2,....
<?PHPInterfaceicaneat{ Publicfunction Eat ($food);}Interfacehello{ Publicfuction Hello ($nihao);}classHuman implements icaneat,hello{#使用逗号隔开即可实现对多个接口的继承 Publicfunction Eat ($food) {echo"I eating". $food."\ n"; }} $test=NewHuman (); $test->eat ('Apple'); ?>
00x3 Case Three
Using instanceof keyword Test
Example: Var_dump ($object instanceof Hello); #对象 $object Whether the Hello interface is implemented
<?PHPInterfacetest{ Publicfunction one ($a);}Interfacetest2{ Publicfunction ($b);}classChengdaniu implements test,test2{ Publicfunction One ($a) {echo"I love Web security technology! "; } Publicfunction ($b) {echo"I want to become Daniel! "; }} $shi=NewChengdaniu (); Var_dump ($shi instanceof test);?>
The output effect is as follows:
Boolean true
The END
Follow Baidu Learn Php[4]oop Face Object programming -12-Object Interface Technology (interface)