Php abstract method and abstract class instance analysis, php abstract class instance analysis
This example describes php abstract methods and abstract classes. We will share this with you for your reference. The details are as follows:
What is an abstract method?
The method defined in the class without a method body is an abstract method. There is no braces and content in the method declaration. In addition, when declaring an abstract method, the keyword abstract is also added.
For example:
Abstract function fun1 (); abstract function fun2 ();
As long as there is an abstract method in the class, this class must be defined as an abstract class.
Abstract classes should also be modified with abstract.
Abstract classes can have non-Abstract methods and member attributes.
However, as long as there is an abstract method, this class must be defined as an abstract class.
How to use abstract classes? The most important thing is the abstract class, which cannot generate instance objects!
Defining an abstract class is equivalent to defining a standard! This specification requires sub-classes to comply with it! After the subclass inherits the abstract class, the abstract methods in the abstract class are implemented according to the requirements of the subclass.
The subclass must implement all the abstract methods in the abstract class. Otherwise, there are still abstract methods in the subclass, subclass or abstract class, or they cannot be instantiated!
<? Phpabstract class Demo {var $ test; abstract function fun1 (); abstract function fun2 (); function fun3 (){...}} class Test extends Demo {function fun1 (){...} function fun2 (){...}} $ test = new Test ();?>