Home > Backend Development > PHP Tutorial > Analysis of key points and precautions for using php abstract classes, php abstraction_PHP tutorial

Analysis of key points and precautions for using php abstract classes, php abstraction_PHP tutorial

WBOY
Release: 2016-07-13 10:07:31
Original
1121 people have browsed it

Analysis of key points and precautions for using php abstract classes, php abstraction

This article analyzes the key points and precautions for using PHP abstract classes through examples. Share it with everyone for your reference. The specific analysis is as follows:

The key points and precautions for using PHP abstract classes are as follows:

1. Use abstract to modify a class, then this class is an abstract class; abstract classes must not be instantiated, that is, $abc = new abstract class name (); will report an error.

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

3. If there is an abstract method in a class, then the class must be defined as an abstract class; but conversely, an abstract class does not necessarily have an abstract method. In addition, abstract classes can also have ordinary methods.

4. Abstract methods cannot have method bodies. That is, abstract function abc();------cannot add curly brackets {..........} after it.

5. If a class inherits an abstract class, it must implement all the abstract methods in the abstract class (unless it also declares these abstract methods as abstract, which is equivalent to the abstract class inheriting the abstract class).

Simple instance of abstract class:

<&#63;php
abstract class Animal{
 public $name;
 protected $price; 
 abstract function cry();
}
class Dog extends Animal{
 function cry(){
 echo "汪汪...";
 }
}
$abc = new Animal();
&#63;>

Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/955402.htmlTechArticleAnalysis of the key points and precautions for the use of php abstract classes, php abstraction This article analyzes the key points and precautions for the use of php abstract classes with examples . Share it with everyone for your reference. The specific analysis is as follows: php pump...
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