大家对具体PHP5抽象类的代码如下:
<ol class="dp-xml"> <li class="alt"><span><span>abstract class AbstractClass { </span></span></li> <li class=""><span> abstract public function test(); </span></li> <li class="alt"><span>} </span></li> <li class=""><span> </span></li> <li class="alt"><span>class ImplementedClass extends AbstractClass { </span></li> <li class=""><span> public function test() { </span></li> <li class="alt"><span> echo "ImplementedClass::test() called. "; </span></li> <li class=""><span> } </span></li> <li class="alt"><span>} </span></li> <li class=""><span> </span></li> <li class="alt"> <span>$</span><span class="attribute"><font color="#ff0000">o</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">new</font></span><span> ImplementedClass; </span> </li> <li class=""> <span>$o-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>test(); </span> </li> </ol>
PHP 5也支持接口的概念,并为之引入了interface和implements关键字。和Java一样,PHP 5使用接口也实现类似于“多重继承”的效果。PHP5接口语法如下:
<ol class="dp-xml"> <li class="alt"><span><span>interface displayable { </span></span></li> <li class=""><span> function display(); </span></li> <li class="alt"><span>} </span></li> <li class=""><span>interface printable { </span></li> <li class="alt"><span> function doprint(); </span></li> <li class=""><span>} </span></li> <li class="alt"><span> </span></li> <li class=""><span>class foo implements displayable,printable { </span></li> <li class="alt"><span> function display() { </span></li> <li class=""><span> // code </span></li> <li class="alt"><span> } function doprint() { </span></li> <li class=""><span> // code </span></li> <li class="alt"><span> } </span></li> <li class=""><span>} </span></li> </ol>
抽象类和PHP5接口的引入使PHP成了一个完全面向对象的语