In PHP object-oriented programming, you will always encounter
class test{ public static function test(){ self::func(); static::func(); } public static function func(){} }
But do you know the difference between self and static?
In fact, the difference is very simple, you only need to write a few demos to understand:
Demo for self:
class Car { public static function model(){ self::getModel(); } protected static function getModel(){ echo "This is a car model"; } }
Car::model();
Class Taxi extends Car { protected static function getModel(){ echo "This is a Taxi model"; } }
Taxi::model();
get From the output
This is a car model This is a car model
, we can see that self will still call the parent class’s method in the subclass. What is called is the method of the parent class, but the method called in the parent class method will also be the method of the subclass (so confusing...)
Before the PHP5.3 version, there was still a little difference between static and self. What is it specifically? , after all, it’s all version 7’s world. I won’t understand it anymore.
The above introduces the difference between self and static in PHP object-oriented programming, including object-oriented programming and static content. I hope it will be helpful to friends who are interested in PHP tutorials.