PHP is the best language in the world
PHP from the process to the now mature object-oriented system, in PHP object-oriented, static variable call We can use these two self::method and Static::method, but many children's shoes confused, do not understand Self::method and static:: What is the difference between method, here are two examples to see exactly:
Example 1:
1 classCar {2 Public Static functionmodel ()3 {4Self::Getmodel ();5 }6 protected Static functionGetmodel ()7 {8 Echo"This is a car model";9 }Ten } OneCar::model ();//This is a car model A Echo' <br/> '; - ClassTaxiextendsCar { - protected Static functionGetmodel () the { - Echo"This is a Taxi model"; - } - } +Taxi::model ();//This is a car model
Summary: Self::getmodel () calls Method Getmodel (), the method of the subclass Getmodel () does not actually mean that the parent class is overloaded with methods Getmodel ().
Example 2:
1 classCar {2 Public Static functionmodel ()3 {4 Static::Getmodel ();5 }6 protected Static functionGetmodel ()7 {8 Echo"This is a car model";9 }Ten } OneCar::model ();//This is a car model A Echo' <br/> '; - ClassTaxiextendsCar { - protected Static functionGetmodel () the { - Echo"This is a Taxi model"; - } - } +Taxi::model ();//This is a Taxi model
Summary: Self::getmodel () calls Method Getmodel (), the method of the subclass Getmodel () overloads the parent class's Method Getmodel ().
Children's shoes, do you understand?
If you have doubts, please comment
The difference between PHP static and self