In this paper, we analyze the static and static methods in the object-oriented PHP call. About their invocation (can be called, how to call), need to figure out where they are stored in memory, so it is very easy to understand. Static properties, methods (both static and non-static) in memory, only one location (not a static property, how many objects are instantiated, and how many properties).
Instance:
<?phpheader ("Content-type:text/html;charset=utf-8"), class human{staticpublic $name = "little Sister"; public$height = 180; Staticpublic Functiontell () {echoself:: $name;//static method call static property, use self keyword//echo $this->height;//error. A static method cannot call a non-static property//Because the $this represents the instantiated object, and here is the class, not knowing which object the $this represents} publicfunction say () {echoself:: $name. "I have spoken"; The normal method calls the static property, also uses the Self keyword echo$this->height; }} $p 1 = new Human (); $p 1->say (); $p 1->tell ();//object can access static method echo $p 1:: $name;//object access static property. You cannot access $p1->name//because the memory location of the static property is not in the object Human::say ();//Wrong. Say () $this error when no $this is available//But php5.4 above will prompt?>
(1), static properties do not need to be instantiated to invoke. Because the static property is stored in a class, the calling method is "class name:: Attribute name"; Conclusion:
(2), static methods do not need to be instantiated to invoke. Ditto
(3), static methods cannot invoke non-static properties. Because the non-static attribute needs to be instantiated, it is stored in the object;
(4), static methods can call non-static methods, using the Self keyword. In PHP, a method is self: after that, it automatically transforms into a static method;