Analysis of the concepts and usage of abstract classes and abstract methods in PHP, php abstraction_PHP tutorial

WBOY
Release: 2016-07-12 08:50:38
Original
993 people have browsed it

Analysis of the concepts and usage of abstract classes and abstract methods in PHP, php abstraction

The examples in this article describe abstract classes and abstract methods in PHP. Share it with everyone for your reference, the details are as follows:

1. Abstract keyword: abstract

Abstract means that it cannot be explained exactly, but it has a certain concept or name. To declare an abstract class or method in PHP, we need to use the abstract keyword.

2. Definition of abstract methods and abstract classes

At least one method in a class is abstract, we call it an abstract class. So if you define an abstract class, first define the abstract method.

abstract class class1{
  abstract function fun1();
……
}

Copy after login

1. There is at least one abstract method in the class
2. Abstract methods are not allowed to have { }
3. Abstract methods must be preceded by abstract

3. Rules for using abstract classes and methods

Several characteristics of abstract classes:

1. cannot be instantiated and can only be inherited
2. In the inherited derived class, all abstract methods must be overloaded before they can be instantiated

Example:

<&#63;php
abstract class cl1{
  abstract function fun1();
  abstract function fun2();
}
class cl2 extends cl1{
  function fun1(){
    echo "第一个";
  }
  function fun2(){
    echo "第二个";
  }
}
$c=new cl2();
echo $c->fun2();
&#63;>

Copy after login

Readers who are interested in more PHP related content can check out the special topics of this site: "Summary of PHP File Operations", "Summary of PHP Operations and Operator Usage", "Summary of PHP Network Programming Skills", "Introduction Tutorial on PHP Basic Grammar" ", "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Summary of PHP date and time usage", "Introduction to PHP object-oriented programming tutorial", "Summary of PHP string (string) usage" , "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"

I hope this article will be helpful to everyone in PHP programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133090.htmlTechArticleAnalysis on the concepts and usage of abstract classes and abstract methods in PHP, php abstraction This article explains the abstract classes and abstractions in PHP with examples method. Share it with everyone for your reference, as follows: 1. Abstraction...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!