In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what are the characteristics of static methods in PHP, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The characteristics of static methods in PHP are: 1, static methods are modified with the static keyword; 2, static methods can be used anywhere in the code; 3, static methods can be accessed without instance objects; 4, static methods can only operate static variables, not non-static variables.
This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.
Characteristics of php static method
Static methods are also called class methods, and static methods belong to all object instances: static function+ method name
Outside the class: class name:: class method name or object name-> class method name
Inside the class: self:: class method name or class name:: class method name
If a variable needs to be shared by all variables, static variables need to be introduced; if a method only manipulates static variables, use static methods
When you manipulate static variables, you need to manipulate static methods, and non-static properties (variables) cannot be accessed in static methods.
Characteristics of static methods:
1. Static methods can only manipulate static methods, not non-static variables.
two。 Ordinary member methods, which can manipulate both non-static and static variables
Advantages of static methods:
(1) it can be used anywhere in the code (assuming the class can be accessed)
(2) each instance of the class can access the static property defined in the class, and the static property can be used to set the value, which can be used by all objects of the class.
(3) static properties or methods can be accessed without an instance object.
Static methods cannot access the normal properties in this class because those properties belong to an object, but can access static properties.
These are all the contents of the article "what are the characteristics of static methods in PHP?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.