Php abstract class usage key points and precautions analysis, php abstract _ PHP Tutorial

Source: Internet
Author: User
Php abstract class usage key points and precautions analysis, php abstract. The main points and precautions for using php abstract classes are analyzed. the example in this article analyzes the main points and precautions for using php abstract classes. Share it with you for your reference. The specific analysis is as follows: php abstract class usage key points and precautions analysis, php abstract

This article analyzes the usage of php abstract classes and points of attention. Share it with you for your reference. The specific analysis is as follows:

The usage of php abstract classes is as follows:

1. if abstract is used to modify a class, this class is an abstract class. an abstract class cannot be instantiated, that is, $ abc = new abstract class name (). an error is returned.

2. if abstract is used to modify a method, the method is an abstract method;

3. if an abstract method exists in a class, the class must be defined as an abstract class. However, abstract classes do not necessarily contain abstract methods. In addition, the abstract class can also contain common methods.

4. abstract methods cannot have method bodies. That is, abstract function abc (); ------ cannot be followed by braces {.........}.

5. if a class inherits an abstract class, it must implement all abstract methods in the abstract class (unless, these abstract methods are declared as abstract, which is equivalent to inheriting the abstract class ).

Simple example of an abstract class:

<? Phpabstract class Animal {public $ name; protected $ price; abstract function cry ();} class Dog extends Animal {function cry () {echo "Wang... ";}}$ abc = new Animal () ;?>

I hope this article will help you with php programming.

Examples this article analyzes the usage of php abstract classes and points of attention. Share it with you for your reference. The specific analysis is as follows: php pumping...

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.