This article mainly introduces the PHP abstract method and abstract class, combined with the example form analysis of the PHP abstract method and abstract class concept, function, definition and use method, the need for friends can refer to the next
Specific as follows:
What is an abstract method?
A method defined in a class that has no method body is an abstract method that does not have curly braces and the contents of the method declaration, plus the keyword abstract to be used when declaring an abstraction.
For example:
Abstract function fun1 (); abstract function fun2 ();
As long as there is an abstract method in the class, the class is defined as an abstract class.
Abstract classes are also decorated with abstract.
Abstract classes can have methods and member properties that are not abstract.
But as long as there is an abstract method, this class must be defined as an abstract class.
How do you use abstract classes? The most important point is the abstract class, which cannot produce an instance object!
Defining an abstract class is equivalent to defining a specification! This type of specification requires subclasses to obey! After the subclass inherits the abstract class, the abstract method in the abstract class is implemented according to the needs of the subclass.
Subclasses must implement all the abstract methods in the abstract class, otherwise there are abstract methods in subclasses, subclasses or abstract classes, or 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 ();? >
The above is the whole content of this article, I hope that everyone's study has helped.