Static problems in PHP Methods

Source: Internet
Author: User
Static is used in the class method. My current problem is that the static variable is saved in the memory. 1. Where is the static variable stored in the memory? 2. How long has the static variable been withdrawn? 3 will excessive static usage cause insufficient server memory? 4. The s... static of different users is used in class methods. My problem now is that the static variable is saved in the memory,
1. Where is the data stored in the memory?
2. How long has the static variable been withdrawn?
3 will excessive static usage cause insufficient server memory?
4. Why does the static variables of different users not affect each other?

Reply content:

Static is used in the class method. My problem now is that the static variable is saved in the memory,
1. Where is the data stored in the memory?
2. How long has the static variable been withdrawn?
3 will excessive static usage cause insufficient server memory?
4. Why does the static variables of different users not affect each other?

When you declare a class method/variable as static, it is bound to and shared by the class, not the object. from a memory management perspective what this means is that when the class definition is loaded into the heap memory, these static objects are created there. when the class's actual object is created in the stack memory and when updates on the static properties are done, the pointer to the heap which contains the static object gets updated. this does help to reduce memory but not by much.

From a programming paradigm, people usually choose to use static variables for your tural advantages more than memory management optimization. in other words, one might create static variables like you mentioned, when one wants to implement a singleton or factory pattern. it provides more powerful ways of knowing what is going on at a "class" level as opposed to what transpires at an "object" level.

Static is stored in the memory. Too much use should cause insufficient memory?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.