- Let me talk about __CLASS __, get_class (), get_called_class () the difference:
__CLASS__ Gets the current class name,
get_class () above, are to get the current class name,
get_called_class () Gets the class name of the current main theme of the class.
Reference program:class A { public function say() { echo 'a is called by'.__CLASS__.'<br/>'; echo 'a is called by'.get_class().'<br/>'; echo 'a is called by'.get_called_class().'<br/>'; } } class B extends A { public function say() { parent::say(); //The method parent :: members call the parent class defined echo ' B Called by IS ' .__ class__. ' a ' ; echo ' B Called by IS ' .get_class (). ' a ' ; echo ' B Called by IS ' . .get_called_class () ' a ' ; } } $ B = new new B; $ B -> say ();
Operating results of the program are:
a is called BYA
a BYA is called
a library is called
b is called BYB
b is called BYB
b is called BYB
- Then late static binding static presentation:
<?php class A { public static function who() { echo __CLASS__; } public static function test() { self::who(); } } class B extends A { public static function who() { echo __CLASS__; } } B::test(); ?> //输出 A class A { public static functionWHO () { echo __CLASS__ ; } public static function Test () { static :: WHO (); // late static binding from here } } class B the extends A { public static function WHO () { echo __CLASS__ ; } } B :: Test (); // now output B
- Details Reference Manual