PHP Interface (interface) and abstract class

Source: Internet
Author: User

Interface

Defines an interface class in which the subclasses of a method must be implemented. An interface is a template for a class whose subclasses must implement all the 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

The abstract class pulls out the parts of the class image, which is to write the repetition into the abstract class and reduce the workload. As long as the method is not declared in abstract, it is not implemented in its subclasses. And in subclasses, the 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.