A few days agoQingyuan educationWhen I see such an article on the website, I feel like I do.Php developersIt is particularly helpful. I am posting it now, hoping to help you. In additionQingyuan educationThere are many such technical articles on the website. if you are interested, you can check them out. Well, let's not talk much about it. let's start with the question: 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. I hope this article will be helpful to the majority of php developers. thank you for reading this article. MorePhp technical problemsWelcome to group discussion:256271784, Verification code:CxyIf you do not write the verification code, it will not pass yo ~
|