PHP abstract class

Source: Internet
Author: User

Make full useAbstract classRules must be kept in mind.

    1. A ClassInclude at least one abstract MethodIt must be declared as an abstract class.
    2. An abstract method must includeSame or lower access level. For example, if the access level of a method in an abstract class is protected, it must be protected or public in the inherited class, rather than private.
    3. The New Keyword cannot be used.Create an instance of an abstract class.
    4. Methods declared as abstractFunction body cannot be included.
    5. If you declare an extended class as an abstract class, you canIn order not to implement all abstract methods.

use abstract modifier can declare a class as abstract.
abstract classes have some limitations. Php only one base class can be inherited. , it does not support inheritance from two or more abstract classes. The ability to inherit from two or more foundation classes is generally referred to as multi-inheritance , PHP is designed to disable this function. The reason is that when two or more classes define the same prototype and have a complete implementation method, inheritance from multiple classes will lead to unnecessary complexity. If you find that you need to inherit from two or more abstract classes, you can disassemble the methods of the base class , and then use interfaces to achieve the same purpose.

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.