Previously found a PHP pervert problem: static (statically) call in PHP non-static method of the detailed
This time to see the next thinkphp source function.inc.php , there is a function:
/** * Get object instance support call static method of class * * @param string $name class name * @param string $method method * @param string $args parameter * @return Object Instance */function get_instance_of ($name, $method = ", $args = Array ()) {Static $_instance = array (); $identify = Empty ($args) ? $name. $method: $name. $method. To_guid_string ($args), if (!isset ($_instance[$identify)) {if (class_exists ($name)) {$o = new $name (); if (method_exists ($o, $method)) {if (!empty ($args)) {$_instance[$identify] = Call_user_func_array (Array (& $o, $method), $args);} else {$_instance[$ Identify] = $o $method ();}} else {$_instance[$identify] = $o;}} else {halt (L (' _class_not_exist_ '). ‘:‘ . $name);}} return $_instance[$identify];}
The function annotation says that it can support the static method of calling the class , from the source surface, the class instance is a static method that cannot invoke the class. However, PHP has to support class instantiation objects to access static methods, but cannot access static properties.
<?phpini_set (' Display_error ', true); error_reporting (e_all); class Dog {public static $name = ' Wangwang '; static function Say ($data) {echo $data;}} $myDog = new Dog (); $myDog->say (' 123456 '); Output 123456echo $myDog->name; Send notice message: Undefined Property:dog:: $name in ...? >
Reference: http://php.net/manual/zh/language.oop5.static.php
"Very sick." The PHP Class instantiation object can access the class's static Method!!!