PHP abstract methods and abstract class examples

Source: Internet
Author: User
This article mainly introduces the PHP abstract method and abstract class, combined with the example form analysis of the PHP abstract method and abstract class concept, function, definition and use method, the need for friends can refer to the next

Specific as follows:

What is an abstract method?

A method defined in a class that has no method body is an abstract method that does not have curly braces and the contents of the method declaration, plus the keyword abstract to be used when declaring an abstraction.

For example:

Abstract function fun1 (); abstract function fun2 ();

As long as there is an abstract method in the class, the class is defined as an abstract class.

Abstract classes are also decorated with abstract.

Abstract classes can have methods and member properties that are not abstract.

But as long as there is an abstract method, this class must be defined as an abstract class.

How do you use abstract classes? The most important point is the abstract class, which cannot produce an instance object!

Defining an abstract class is equivalent to defining a specification! This type of specification requires subclasses to obey! After the subclass inherits the abstract class, the abstract method in the abstract class is implemented according to the needs of the subclass.

Subclasses must implement all the abstract methods in the abstract class, otherwise there are abstract methods in subclasses, subclasses or abstract classes, or cannot be instantiated!

<?phpabstract class Demo{var $test, abstract function fun1 (), abstract function fun2 (), function Fun3 () {    ...  }} Class Test extends Demo{function fun1 () {   ...} function fun2 () {   ...}} $test = new test ();? >

The above is the whole content of this article, I hope that everyone's study has helped.


Related Article

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.