Introduction to PHP5 interface and PHP5 abstract class syntax

Source: Internet
Author: User

ForThe code for the specific PHP5 abstract class is as follows:

 
 
  1. abstract class AbstractClass {     
  2.    abstract public function test();     
  3. }     
  4.     
  5. class ImplementedClass extends AbstractClass {     
  6.    public function test() {     
  7.        echo "ImplementedClass::test() called. ";     
  8.    }     
  9. }     
  10.     
  11. $o = new ImplementedClass;     
  12. $o->test();    

PHP 5 also supports the interface concept and introduces the interface and implements keywords for it. Like Java, PHP 5 uses interfaces to achieve the same effect as "Multi-inheritance. The PHP5 interface syntax is as follows:

 
 
  1. interface displayable {     
  2.   function display();     
  3. }     
  4. interface printable {     
  5.   function doprint();     
  6. }     
  7.     
  8. class foo implements displayable,printable {     
  9.   function display() {     
  10.     // code     
  11.   }   function doprint() {     
  12.     // code     
  13.   }     
  14. }    

The introduction of abstract classes and PHP5 interfaces makes PHP a fully object-oriented language.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.