Home >Backend Development >PHP Tutorial >PHP多个接口同个方法

PHP多个接口同个方法

PHP中文网
PHP中文网Original
2016-05-19 12:16:021330browse



如果有多个接口有一个相同的方法名,且不是继承出来的,PHP是不允许的

如下实例:


interface a{

  public function x();

}

interface b{

  public function x();

}

class c implements a,b{

  public function x();

}


 


报如下错误: Can't inherit abstract function b::x() (previously declared abstract in c)

如果要实现不同接口有相同的方法,可以如下实现:


interface d{

  public function x();

}

interface a extends d{}

interface b extends d{}

class c implements a,b{

  public function x(){

    echo "succ";

  }

}


 以上就是PHP多个接口同个方法的内容,更多相关内容请关注PHP中文网(www.php.cn)!


通过腾讯QQ微博API接口获取微博内容
 

http://tech.cncms.com/web/php/23492.html



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