This article brings to you the content is about the static method and static properties of the introduction of PHP, there is a certain reference value, the need for friends can refer to, I hope to help you.
Static is divided into two parts: static properties and Static methods
Static things are for class (including class constants), non-static is for the object
Static properties
When defining a property, a property that uses the static modifier of the keyword is called a static property.
Static methods
Methods that are decorated with the static keyword are called static methods.
Can solve the problem with static, no ordinary method to solve the problem (static things can directly use the class access, do not need to instantiate through the object, thus saving memory space, improve efficiency).
Special attention:
In the process of writing code, strictly follow the case specification
Strictly follow: Static content to the class access, non-static is to the object access, do not cross-boundary operation
Third, the difference between self and $this
1. Self represents class, $this represents object
2. Self accesses constant and static properties and static methods inside the class, $this accessing the object's properties and common methods
3, self must cooperate with the scope resolution operator (::) to take effect, $this represents the object, the object is a data type, so $this can be printed separately.
4, can use the place of $this, must be able to using self, but can use self of place not necessarily can use $this
5. Non-static properties and methods are accessed using the object ($this), and static methods and properties or constants are accessed using the Class (self)