Analysis of abstract classes and abstract methods in PHP, and php abstraction. The abstract class and abstract method in PHP are analyzed in terms of concepts and usage. the example in this article describes the abstract class and abstract method in php. For your reference, I. abstract the concept and usage of abstract classes and abstract methods in PHP, and php abstraction
This example describes the abstract classes and abstract methods in PHP. We will share this with you for your reference. The details are as follows:
I. abstract Keywords: abstract
Abstraction cannot be specified, but there are certain concepts or names. to declare an abstract class or method in PHP, we need to use the adstract keyword.
II. definition of abstract methods and abstract classes
At least one method in a class is abstract, which is called an abstract class. Therefore, if an abstract class is defined, the abstract method is first defined.
Abstract class class1 {abstract function fun1 ();......}
1. there must be at least one abstract method in the class.
2. abstract methods cannot have {}
3. abstract must be added before the abstract method.
III. rules for using abstract classes and methods
Abstract classes have the following features:
1. it cannot be instantiated and can only be inherited
2. all abstract methods must be reloaded in the inherited derived classes before they can be instantiated.
Instance:
<? Phpabstract class cl1 {abstract function fun1 (); abstract function fun2 ();} class cl2 extends cl1 {function fun1 () {echo "first";} function fun2 () {echo "second" ;}}$ c = new cl2 (); echo $ c-> fun2 ();?>