Today, the boss in the company asked a new static and new self of the difference between the company 10 programs did not have an answer up the back of the screen to fill ...
This cock silk home after Baidu understand the following two differences:
Use self :: or __class__ a static reference to the current class, depending on the class in which the current method is defined:
Use static:: is no longer resolved to define the class in which the current method resides, but is calculated at the actual run time. It can also be called a "static binding" because it can be used (but not limited to) the invocation of a static method.
In simple terms, self is written in which class, which is actually called the class. The so-called late static binding, static represents the class used, is the static you write in the parent class,
This static is then used directly/indirectly through the subclass, which is the subclass, so static and $this are much like, but static can be used for methods and properties.
Look at the list.
PHPclass person{ publicstaticfunction name () { echo "Xiaosan"; } Public Static function callself () { self::name (); } Public Static function callstatic () { static::name (); }} class extends person{ publicstaticfunction name () { Echo "Gaojin"; }} man:: Name (); // Output:gaojin Person::callself (); // Output:xiaosan Person::callstatic (); // Output:gaojin?>
Keep Learning in small series
The above introduces the difference between new static and new self in PHP, including the contents of the content, I hope that the PHP tutorial interested in a friend helpful.