Examples of PHP interface features _php tutorial

Source: Internet
Author: User
We are learning throughvideocard.php interface file (function interface definition for graphics card)

 
  
  
  1. Php
  2. Interface videocardinter{
  3. function Display ();
  4. function GetName ();
  5. }
  6. ?>

Dmeng.php implementation interface (deem manufacturers realize these interfaces, how to achieve, motherboard manufacturers do not tube)

 
  
  
  1. Php
  2. Include_once ("videocard.php");
  3. Class Dmeng implements Videocardinter {
  4. function Display () {
  5. echo "Display";
  6. }
  7. function GetName () {
  8. Return "Dmeng Videocard";
  9. }
  10. }
  11. ?>

mainboard.php Application Interface (plug the graphics card into the motherboard, the motherboard as long as the use of these interfaces on the line, also can not be used)

 
 
  1. php
  2. Include_once ("videocard.php");
  3. Include_once ("dmeng.php");
  4. Class mainboard{
  5. var $vc;
  6. function run (Videocardinter $VC) {//Defines the Videocardinter interface type parameter, and does not know who will implement it.
  7. $this- > VC = $VC;
  8. $this- > vc- > Display ();
  9. echo "Motherboard running! ";
  10. }
  11. }
  12. $ Conputer = New mainboard ();
  13. $conputer- > Run (new Dmeng); To write the name of the implementation interface class in the
    (now it is deem's video card, can also be replaced by other field home, as long as they have implemented the interface)
  14. ?>

Because PHP is a dynamic language, so the type can not be the same as Java is dead, when defining the interface, write the return type error, it is estimated that the PHP6 may be written to be more strict.

PS: I only write the most basic parts of PHP interface features, you can also add CPU and other interfaces.


http://www.bkjia.com/PHPjc/446410.html www.bkjia.com true http://www.bkjia.com/PHPjc/446410.html techarticle We are learning videocard.php interface file (the function interface definition of graphics card)? PHP interfacevideocardinter{Functiondisplay (); Functiongetname ();}? dmeng.php implementation interface (Emperor ...

  • 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.