Heim  >  Artikel  >  Backend-Entwicklung  >  PHP多个接口同个方法_PHP教程

PHP多个接口同个方法_PHP教程

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

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

  如下实例:

  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)

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

  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.htmlTechArticle如果有多个接口有一个相同的方法名,且不是继承出来的,PHP是不允许的 如下实例: php; interface a{ public function x(); } interface b{ public function x()...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn