Reason: uncertainty of the parent class
Why design the abstract class technology?
1.In actual development, we may have such a class, which is the parent class of other classes, but it itself does not need to be instantiated , and its main purpose is to let children Classes are inherited to achieve code reuse and at the same time benefit project designers in designing classes.
2.Keywords:abstract
3.Basic usage:
abstract class class name
{//method
//attribute
function Function name(Parameter list) ; /*abstract modifier
functionfunction name(parameter list) { echo " This way of writing is wrong!
";//Because there is an extra method body} */ } abstract
modified a class, this class is called an abstract class;abstractModify a method, this class is called an abstract method [If it is an abstract method, it cannot have a method body];
4.Notes
:a
.Abstract classes can have no abstract methods, and can also have implemented methods (complete functions); b.
Once a method is declaredabstractmethod, the class must be declared as abstract
class , that is, theabstract class name corresponds to the abstract method; c.If a class inherits an abstract class, it must inherit all of the abstract class
Abstract method, unless it is an abstract class;Case 1:
abstract class Animal //parent class
{
public $name; protected $price; abstractpublic function cry();
//There is no method body. This method is mainly for subclasses to implement} class Dog extends Animal //
subclass{
public function cry()//
subclass inherits parent class method{echo " Small The dog is barking! The above has introduced PHP abstract classes, including PHP and abstract class content. I hope it will be helpful to friends who are interested in PHP tutorials.