Php abstract class usage key points and precautions analysis, php abstract. The main points and precautions for using php abstract classes are analyzed. the example in this article analyzes the main points and precautions for using php abstract classes. Share it with you for your reference. The specific analysis is as follows: php abstract class usage key points and precautions analysis, php abstract
This article analyzes the usage of php abstract classes and points of attention. Share it with you for your reference. The specific analysis is as follows:
The usage of php abstract classes is as follows:
1. if abstract is used to modify a class, this class is an abstract class. an abstract class cannot be instantiated, that is, $ abc = new abstract class name (). an error is returned.
2. if abstract is used to modify a method, the method is an abstract method;
3. if an abstract method exists in a class, the class must be defined as an abstract class. However, abstract classes do not necessarily contain abstract methods. In addition, the abstract class can also contain common methods.
4. abstract methods cannot have method bodies. That is, abstract function abc (); ------ cannot be followed by braces {.........}.
5. if a class inherits an abstract class, it must implement all abstract methods in the abstract class (unless, these abstract methods are declared as abstract, which is equivalent to inheriting the abstract class ).
Simple example of an abstract class:
<? Phpabstract class Animal {public $ name; protected $ price; abstract function cry ();} class Dog extends Animal {function cry () {echo "Wang... ";}}$ abc = new Animal () ;?>
I hope this article will help you with php programming.
Examples this article analyzes the usage of php abstract classes and points of attention. Share it with you for your reference. The specific analysis is as follows: php pumping...