PHP interface and abstract)

Source: Internet
Author: User

Interface

Defines an interface class, and its subclass must be implemented. An interface is a template of a class. Its subclass must implement all methods defined in the interface.

Interface User {

Function getHeight ($ height );

Function getWeight ($ weight );

}

Class my implements User {

Function getHeight ($ username ){

Echo $ height;

}

Function getWeight ($ weight ){

Echo $ weight;

}

}

Abstract

Abstract classes extract the class image part, that is, writing repeated items to abstract classes to reduce the workload. As long as the method does not use abstract declaration, it does not need to be implemented in its subclass. In the subclass, this method is a public method.

Abstract User {

Abstract function getHeight ($ height );

Function getWeight (){

Echo $ weight;

}

}

Class my extends User {

Function getHeight ($ height ){

Echo $ height;

}

Function getInfoById ($ id ){

$ This-> getWeight. "<br/> ";

Echo $ id;

}

}

 

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.