PHP abstract class use points and considerations analysis, PHP abstract _php Tutorial

Source: Internet
Author: User

PHP abstract class use points and considerations analysis, PHP abstract


This article analyzes the use of PHP abstract class points and considerations. Share to everyone for your reference. The specific analysis is as follows:

PHP abstract class use points and considerations are as follows:

1, using abstract to modify a class, then this class is abstract class, abstract class can never be instantiated, that is, $ABC = new abstract class name (); error.

2, using abstract to modify a method, then the method is an abstract method;

3, if there is an abstract method in the class, then the class must be defined as an abstract class, but in turn, abstract classes do not necessarily have abstract methods. In addition, abstract classes can also have common methods.

4, abstract methods can not have method body. That is, abstract function abc ();------cannot be appended with parentheses {...}.

5. A class inherits an abstract class, so it must implement all the abstract methods in the abstract class (unless it is also declared abstract, which is equivalent to an abstract class inheriting an abstract class).

Abstract class Simple example:

<?phpabstract class animal{public $name; protected $price;  abstract function Cry ();} Class Dog extends animal{function cry () {echo "Barking ...";}} $ABC = new Animal ();? >

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/955402.html www.bkjia.com true http://www.bkjia.com/PHPjc/955402.html techarticle PHP abstract class use points and considerations for analysis, PHP abstract This article analyzes the use of PHP abstract class points and considerations. Share to everyone 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.