Heim  >  Artikel  >  Backend-Entwicklung  >  php基础~

php基础~

WBOY
WBOYOriginal
2016-06-13 10:16:40906Durchsuche

php基础求助~~~~
有个问题是关于继承和接口的?~~~~~~~

我有个class person implements ispeak{public function speak(){echo "人说话";}}类,
鸟类class bird implements ispeak{public function speak(){echo "鸟叫";}}类 
 接口ispeak{public function speak();}

我一个艺人类 yrPerson extends person {} 
因为艺人可以学鸟叫 我现在想让艺人也可以鸟叫 但不要重复写代码public function speak(){echo "鸟叫";}


高手给讲讲!!!!急呀 经理总说我代码重复率太高了~~~~~


------解决方案--------------------
忘了要继承person类,小改一下

PHP code
class yrPerson extends person{    //添加口技方法...    public function show($a){        $func=Factory::func($a);        return $func->speak();    }}$person=new yrPerson();$person->speak();        //自己说话$person->show('dog');    //学狗叫$person->show('bird');    //学鸟叫//接着学...<div class="clear">
                 
              
              
        
            </div>
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