Home >Backend Development >PHP Tutorial >Introduction to the syntax of PHP5 interface and PHP5 abstract class_PHP tutorial

Introduction to the syntax of PHP5 interface and PHP5 abstract class_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:28:56882browse

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


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446413.htmlTechArticleThe code for the specific PHP5 abstract class is as follows: abstractclassAbstractClass{ abstractpublicfunctiontest(); } classImplementedClassextendsAbstractClass{ publicfunctiontest(){ echo "Im...
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