Abstract class and abstract method concepts and usage analysis in PHP, PHP abstract _php Tutorial

Source: Internet
Author: User
Tags getting started with php

Abstract class and abstract method concepts and usage analysis in PHP, PHP abstraction


The examples in this article describe abstract classes and abstract methods in PHP. Share to everyone for your reference, as follows:

Abstract Key Words: Abstraction

Abstract is not an exact description, but there is a certain concept or name, in PHP to declare an abstract class or method we need to use the Adstract keyword.

II. definitions of abstract methods and abstract classes

At least one of the methods in a class is abstract, which we call abstract classes. So if you define an abstract class, you first define an abstract method.

Abstract class class1{  abstract function fun1 ();

1. There is at least one abstract method in the class
2. The abstract method does not allow {}
3. abstract methods must be added before

III. rules for the use of abstract classes and methods

Several features of abstract classes:

1, can not be instantiated, can only be inherited
2. inherit all abstract method overloads in the derived class to instantiate

Instance:

<?phpabstract class cl1{  abstract function fun1 ();  Abstract function fun2 ();} Class Cl2 extends cl1{  function fun1 () {    echo "first";  }  function fun2 () {    echo "second";  }} $c =new Cl2 (); Echo $c->fun2 ();? >

More about PHP related content readers can view the topic: "PHP File Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document tips summary (including word, excel,access,ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1133090.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133090.html techarticle abstract class and abstract method concepts and usage analysis in PHP, PHP abstract This article describes the abstract classes and abstract methods in PHP. Share to everyone for your reference, specific as follows: First, abstract off ...

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