Everyone’s code for the specific PHP5 abstract class is as follows:
<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 also supports the concept of interfaces , and introduced the interface and implements keywords. Like Java, PHP 5 uses interfaces to achieve an effect similar to "multiple inheritance". The PHP5 interface syntax is as follows:
<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>
The introduction of abstract classes and PHP5 interfaces makes PHP a completely object-oriented language