In the object-oriented programming of PHP, 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, just need to write a few demo can 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 output
This was a car modelthis is a car model
It can be found that self in a subclass still calls the parent class's method
Demo for static
Class car{public static function model () { static::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 output
This was a car modelthis is a Taxi model
As you can see, in the call to static, the subclass even calls the method of the parent class, but the method called in the parent class method is also a method of the subclass (good Raozui: )
Before the PHP5.3 version, static and self still have a little difference, specifically what, after all, is the 7 version of the world. Don't get to know it.
The summary is that self can only refer to methods in the current class, while the static keyword allows a function to dynamically bind methods in a class at run time.
The above describes the PHP object-oriented programming self and static differences, including object-oriented programming, static content, I hope the PHP tutorial interested in a friend helpful.