As shown below:
<?phpheader (' content-type:text/html;charset=utf-8 ');/* Normal method, storage class, only a static method, is also stored in the class, only one difference is: The ordinary method requires the object to call, need to bind $ This is, the normal method, must have the object, and then let the object to invoke the static method, which does not belong to which object, so do not need to bind $this that is, do not need the object can also call */class human{static public $head = 1; Public Function Easyeat () {echo ' common method meal <br/> '; } static Public Function eat () {echo ' static method eats <br/> '; } public Function Intro () {echo $this->name; }}error_reporting (e_all| E_STRICT);//There are no objects at this time! The method can execute Human::eat ();/* The following method Easyeat is a non-static method that is called by the object, but it can also be executed using the class to invoke this method, while in strict state this method executes with an error, STRICT standards: Non-static method Human::easyeat () should not being called statically in D:\application\PHPnow-1.5.6\htdocs\yan18\types\ staticfun.php on line */human::easyeat ();/* Connect, from the logic to understand, if the class name static call non-static (normal) method such as: Intro () So, this $this refers to which object?? This will result in an error because the object cannot be found! Fatal error:using $this When not in object context in D:\application\PHPnow-1.5.6\htdocs\yan18\types\staticfun.php on Lin e 23*/human::intro (); /* As above analysis, in fact, non-static method can not be called statically by the class name, but at present, the object-oriented detection in PHP is not strict enough, as long as the static method does not have $this keyword, it will be converted to static method to deal with! */$Li=new Human (); $li->eat (); /* Summary: Class Access-static method (method of Class)--class access---general method (method of object)------------------------No, although the method does not use $this keyword! But this is not supported) object access static method (method of Class)-can object Access "common method (object method)---" */?>
The above is a small series for everyone to discuss the PHP static method and the common method of the difference between the whole content, I hope that we support topic.alibabacloud.com~