In PHP, static methods are defined in a class and modified by the static keyword. They only belong to the class itself and are not methods of objects of this class; ordinary methods are defined in a class. , a method that can be called for all objects of this class.
Recommended: "PHP Video Tutorial"
Ordinary method (instance method)
A method defined in a class can be called for all objects of this class. It can also be understood that all objects of this class have their own method;
Definition form:
class 类名{ function 方法名(形参1,形参2,.... ){ //方法体。。。 } }
Calling form:
$对象名->方法名(实参1,实参2,....);
Static method
The method defined in a class only belongs to the class itself, not to the objects of this class .
Definition form:
class 类名{ static function 方法名(形参1,形参2,.... ){ //方法体。。。 } }
Calling form:
类名::方法名(实参1,实参2,....);
Example (comprehensive example of properties and methods)
Related recommendations: php training
The above is the detailed content of What are static methods and ordinary methods in php. For more information, please follow other related articles on the PHP Chinese website!