The following small series will give you a detailed description of the differences between php static methods and common methods. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the following:
';} Static public function eat () {echo' static method for dinner
';} Public function intro () {echo $ this-> name ;}} Error_reporting (E_ALL | E_STRICT); // no object at this time! The method can execute Human: eat ();/* The following method easyeat is a non-static method, which is called by the object. However, it can also be executed to call this method using classes, in a Strict state, this method is executed and an error is reported at the same time. Strict Standards: Non-static method Human: easyeat () shoshould not be called statically in D: \ application \ PHPnow-1.5.6 \ htdocs \ yan18 \ types \ staticfun. php on line 32 */Human: easyeat ();/*. it can be understood from the logic. if the class name is used to call a non-static (common) method statically, for example, intro () which object does this $ this mean ?? Therefore, an error is reported 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 line 23 */Human: intro ();/* in the above analysis, in fact, non-static methods cannot be called statically by class names, but currently, the object-oriented detection in php is not strict enough. as long as there is no $ this keyword in the static method, it will be converted into a static method for processing! */$ Li = new Human (); $ li-> eat ();/* Summary: Class access-> static method (class method) -> Class access-> Common method (object method)-> no (although the $ this keyword is not used in the method, yes! But this method is not supported.) access to object static method (class method)-> access to object normal method (object method)-> Yes */?>
The above is all about the differences between static php methods and common methods. I hope you can support PHP ~
For more details about the differences between php static methods and common methods, please refer to the PHP Chinese website!