PHP new Self () and new Static (), phpnewselfstatic
class A { publicstaticfunction get_self () { returnNew self (); } Public Static function get_static () { returnnewstatic(); class extends echoget_class// Aechoget_class // B
Echo Get_class // A
Self refers to the parsing context, not the calling context. In the example, self is parsed into a that defines get_self (), rather than the B that resolves to call self.
The concept of lazy static binding is introduced in php5.3, and the most obvious sign of this feature is the new keyword static. Static refers to the class being called. In the example, b::get_static () will produce a new B, instead of instantiating a
http://www.bkjia.com/PHPjc/1112811.html www.bkjia.com true http://www.bkjia.com/PHPjc/1112811.html techarticle php New Self () and new Static (), Phpnewselfstatic class A {public static function get_self () {return-new self (); static function Get_static () {return new static ();}} C ...