Example explanation of PHP interface features_PHP tutorial
We are learning the VideoCard.php interface file (functional interface definition of the graphics card)
<ol class="dp-xml"><li class="alt"> <span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>interface VideoCardInter{ </SPAN><LI class=alt><SPAN> function Display(); </SPAN><LI class=""><SPAN> function getName(); </SPAN><LI class=alt><SPAN>} </SPAN><LI class=""><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span> </li></ol>
Dmeng.php implements the interface (the manufacturers of Diamond have implemented these interfaces. How to implement them is not a matter of the motherboard manufacturer)
<ol class="dp-xml"><li class="alt"> <span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>include_once("VideoCard.php"); </SPAN><LI class=alt><SPAN>class Dmeng implements VideoCardInter { </SPAN><LI class=""><SPAN> function Display(){ </SPAN><LI class=alt><SPAN> echo "Display"; </SPAN><LI class=""><SPAN> } </SPAN><LI class=alt><SPAN> function getName(){ </SPAN><LI class=""><SPAN> return "Dmeng VideoCard"; </SPAN><LI class=alt><SPAN> } </SPAN><LI class=""><SPAN>} </SPAN><LI class=alt><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span> </li></ol>
Mainboard.php application interface (insert the graphics card into the motherboard, the motherboard only needs to use these interfaces, or not)
<ol class="dp-xml"> <li class="alt"> <span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>include_once("VideoCard.php"); </SPAN><LI class=alt><SPAN>include_once("Dmeng.php"); </SPAN><LI class=""><SPAN>class Mainboard{ </SPAN><LI class=alt><SPAN> var $vc; </SPAN><LI class=""><SPAN> function run(VideoCardInter $vc){ //定义VideoCardInter接口类型参数,这时并不知道是谁来实现。 </SPAN><LI class=alt><SPAN> $this-</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong></span><span class="attribute"><font color="#ff0000">vc</font></span><span>=$vc; </span> </li> <li class=""> <span> $this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>vc-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>Display(); </span> </li> <li class="alt"><span> echo "主板运行!"; </span></li> <li class=""><span> } </span></li> <li class="alt"><span>} </span></li> <li class=""> <span>$</span><span class="attribute"><font color="#ff0000">conputer</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">new</font></span><span> Mainboard(); </span> </li> <li class="alt"> <span>$conputer-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>run(new Dmeng); //用的时候把实现接口类的名称写进来,<br>(现在是帝盟的显卡,也可以换成别的场家的,只要他们都实现了接口) </span> </li> <li class=""> <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>
Since PHP is a dynamic language, the type cannot be like JAVA The definition is very rigid. When defining the interface, it will make an error to write the return type. I guess in PHP6, the definition may be more strict.
PS: I only wrote the most basic part of the PHP interface features, and you can also add CPU and other interfaces.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
