PHP Tutorial-php Interface Declaration and use

Source: Internet
Author: User
Tags abstract inheritance php tutorial

The seventh chapter (13) The Declaration and use of object-oriented detailed _ interface
Interface interface Name {All attributes must be constants, all methods must be abstract, all members must be public}
The function of an interface: is a specification.
Use the implements< Inheritance interface keyword when implementing an interface.
You can use an abstract class to implement some of the methods of an interface.
Use the class to implement all the methods in the interface.
Use instances of interfaces:
interface< declaration Interface Keywords > Ren1
{
Const xingming= "John";
function shuohua1 ();
function Shuohua2 ();
}
Interface Ren2 extends< interface inheritance interface can use inherited keywords > Ren1
{
function Shuohua3 ();
function shuohua4 ();
}
Interface Ren3{function shuohua5 ();}
Interface Ren4{function shuohua6 ();}
Class Ren5{function Shuohua7 () {echo "7777<br>";}}
Class Ren extends Ren5 implemenrs< inherits the interface's keywords, you must first inherit the classes and inherit the interfaces, you can inherit multiple interfaces at the same time > Ren2,ren3,ren4
{
function shuohua1 () {echo "1111<br>";}
function Shuohua2 () {echo "2222<br>";}
function Shuohua3 () {echo "3333<br>";}
function shuohua4 () {echo "4444<br>";}
function Shuohua5 () {echo "5555<br>";}
function Shuohua6 () {echo "6666<br>";}
< Complete all inherited abstract methods >
}
$r =new Ren (); echo ren::xingming. " <br> ";
$r->shuohua1 ();  $r->shuohua2 ();  $r->shuohua3 ();  $r->shuohua4 ();  $r->shuohua5 ();  $r->shuohua6 (); $r->shuohua7 ();
Instance output results:
Zhang 31,111 2222 3333 4444 5555 6666 7777

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.