In php, there are two methods for methods/variables of the callback class:
1. Create an object $ object = new Class () and then use "->" to call: $ object-> attribute/function, provided that the variable/method is accessible.
2. directly call the class method/variable: class: attribute/function, either static or non-static. However, there are prerequisites:
A. If it is A variable, the variable must be accessible.
B. If it is a method, in addition to the method that can be accessed, it also needs to meet the following requirements:
B1) if it is a static method, there are no special conditions;
B2) if it is a non-static method, $ this is not used in the method to be modified, that is, non-static variables/methods are not called. Of course, there is no problem in calling static variables/methods.
Then let's take a look at using $ object->... And use class ::... Are there any differences:
1. Use $ object->... , You need to execute the constructor to create an object;
2. Use class ::... Call static methods/variables without executing constructors to create objects;
3. Use class ::... Call non-static methods/variables, and do not need to execute constructors to create objects.
Then it came out in a strange way. Since both 2 and 3 are the same, what is the significance of static methods/variables?
The difference still exists as follows:
1. Static variables
Static members only retain one variable value, which is valid for all instances, that is, all instances share this member.
2. Static Method
Static methods can directly use class ::... Instead of static methods, you must meet certain conditions to use the class:... method call, as described earlier