Abstract method refers to a method defined in a class without a method body. If a method in a class is an abstract method, then the class is an abstract class, and abstract classes can contain non-abstract methods. When declaring abstract methods and abstract classes, you need to use the abstract keyword to modify them.
#What is an abstract method?
(Recommended tutorial: php tutorial)
The method we define in the class without a method body is an abstract method. The so-called no method body means that there are no curly braces and the contents inside when declaring, but directly adding a semicolon after the method name when declaring. In addition, when declaring an abstract method, the method also needs to add a keyword. "abstract" to modify.
For example:
abstract function fun1(); abstract function fun2();
What is an abstract class?
As long as a method in a class is an abstract method, then the class is defined as an abstract class, and the abstract class must also be modified with the "abstract" keyword; in an abstract class, there can be methods that are not abstract and Member attributes, but as long as one method is abstract, the class must be declared as an abstract class and decorated with "abstract".
For example:
abstract class demo{ var $test; abstract function fun1(); abstract function fun2(); }
The above is the detailed content of What are abstract methods and abstract classes in php. For more information, please follow other related articles on the PHP Chinese website!