Analysis of abstract classes and abstract methods in PHP, php abstraction _ PHP Tutorial

Source: Internet
Author: User
Analysis of abstract classes and abstract methods in PHP, and php abstraction. The abstract class and abstract method in PHP are analyzed in terms of concepts and usage. the example in this article describes the abstract class and abstract method in php. For your reference, I. abstract the concept and usage of abstract classes and abstract methods in PHP, and php abstraction

This example describes the abstract classes and abstract methods in PHP. We will share this with you for your reference. The details are as follows:

I. abstract Keywords: abstract

Abstraction cannot be specified, but there are certain concepts or names. to declare an abstract class or method in PHP, we need to use the adstract keyword.

II. definition of abstract methods and abstract classes

At least one method in a class is abstract, which is called an abstract class. Therefore, if an abstract class is defined, the abstract method is first defined.

Abstract class class1 {abstract function fun1 ();......}

1. there must be at least one abstract method in the class.
2. abstract methods cannot have {}
3. abstract must be added before the abstract method.

III. rules for using abstract classes and methods

Abstract classes have the following features:

1. it cannot be instantiated and can only be inherited
2. all abstract methods must be reloaded in the inherited derived classes before they can be instantiated.

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 ();?>

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.