Home > Backend Development > PHP Tutorial > Understand the significance of interface in PHP interface_PHP tutorial

Understand the significance of interface in PHP interface_PHP tutorial

WBOY
Release: 2016-07-21 15:03:08
Original
855 people have browsed it

Maybe everyone knows this, but as someone who doesn’t understand, I guessed the meaning of this interface. It is to call the content that exists in the interface in the implementation class in the method that is called later. It’s so confusing. I’ll leave it with an example. Let’s take a look at it later
pay.php

Copy code The code is as follows:

interface Ipay
{
function withmoney();

//function withinternet();
}
class Dmeng implements Ipay
{

function withmoney()
{
echo "Spend RMB to buy things";
}
function withinternet()
{
return "Pay with online banking";
}
}

usei.php
Copy code The code is as follows:

include_once 'pay.php';
class main
{
function run($vc)
{
$this->vc = $vc;
$this->vc->withinternet();
echo "yunxing ";
}

}
$com= new main();
$com->run(new Dmeng);

Just like the above , we commented out a certain method in the interface, and found that it was useless when we called it again

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327878.htmlTechArticleMaybe everyone knows this. As someone who doesn’t understand, I guessed the meaning of this interface. It is for later calling When calling, call the method that exists in the interface in the implementation class...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template