Abstract class and abstract method concepts and usage analysis _php techniques in PHP

Source: Internet
Author: User
Tags abstract

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

One, abstract key words: abstract

Abstraction is not an exact description, but there is a certain concept or name, in PHP to declare an abstract class or method we need to use the Adstract keyword.

Definitions of abstract methods and abstract classes

At least one of the methods in a class is abstract, which we call an abstract class. So if defining an abstract class first defines an abstract method.

Abstract class class1{
  abstract function fun1 ();
...
}

1. There is at least one abstract method in the class
2, the abstract method does not allow {}
3, the abstract method must be added abstract before

Iii. abstract class and method usage rules

Several features of abstract classes:

1, cannot be instantiated, can only be inherited
2, in the inherited derived class, all abstract method overloads are to be instantiated

Instance:

<?php
abstract class cl1{
  abstract function fun1 ();
  Abstract function fun2 ();
}
Class Cl2 extends cl1{
  function fun1 () {
    echo "first";
  }
  function fun2 () {
    echo ' second ';
  }
}
$c =new Cl2 ();
echo $c->fun2 ();
? >

More interested in PHP related content readers can view the site topics: "PHP file Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "Basic PHP Grammar Introduction Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"

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.