PHP Abstract method and abstract class instance analysis _php skill

Source: Internet
Author: User
Tags abstract

The examples in this article describe the PHP abstract methods and abstract classes. Share to everyone for your reference, specific as follows:

What is an abstract method?

A method that is defined within a class without a method is an abstract method that does not have curly braces and the contents of the method declaration, plus the keyword abstract when declaring the abstract method.

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 also need to be decorated in abstract.

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

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

How does an abstract class work? The most important point is the abstract class, cannot produce the instance Object!

Defining an abstract class is equivalent to defining a specification! This specification requires subclasses to follow! 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 abstract methods in an abstract class, or there are abstract methods in subclasses, subclasses or abstract classes, or not instantiated!

<?php
abstract class demo{
var $test;
Abstract function fun1 ();
Abstract function fun2 ();
function Fun3 () {
    ...}}
Class Test extends demo{
function fun1 () {
   ...
}
function fun2 () {
   ...}}
$test = new test ();
? >

More about PHP Interested readers can view the site topics: "PHP object-oriented Program Design Primer", "PHP basic Grammar Introductory Course", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Array" operation Skills Encyclopedia, " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips

I hope this article will help you with the PHP program design.

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.