Home  >  Article  >  Backend Development  >  PHP multiple interfaces with the same method_PHP tutorial

PHP multiple interfaces with the same method_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:17:231098browse

If there are multiple interfaces with the same method name and they are not inherited, PHP is not allowed

The following examples:

 php;">

interface a{

public function x();

 }

interface b{

public function x();

 }

class c implements a,b{

public function x();

 }

The following error is reported: Can't inherit abstract function b::x() (previously declared abstract in c)

If you want to implement different interfaces with the same method, you can implement it as follows:

 php;">

Interface d{

public function x();

 }

interface a extends d{}

interface b extends d{}

class c implements a,b{

public function x(){

echo "succ";

 }

 }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371991.htmlTechArticleIf there are multiple interfaces with the same method name and they are not inherited, PHP is not allowed as follows Example: php; interface a{ public function x(); } interface b{ public function x()...
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