首页 / PHP / 关于PHP中方法中的static的问题
关于PHP中方法中的static的问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了关于PHP中方法中的static的问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1419字,纯文字阅读大概需要3分钟。
内容图文
![关于PHP中方法中的static的问题](/upload/InfoBanner/zyjiaocheng/238/0220c657c1ef41e397a897cedca138d7.jpg)
1 具体保存在内存中的哪个地方?
2 这个static的变量多长时间被收回?
3 过多的使用的static会不会造成服务器内存不够?
4 不同的用户的static变量为什么会互不影响?
回复内容:
static用在类的方法中,我现在的问题是static的这个变量是保存在内存中,
1 具体保存在内存中的哪个地方?
2 这个static的变量多长时间被收回?
3 过多的使用的static会不会造成服务器内存不够?
4 不同的用户的static变量为什么会互不影响?
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 architectural 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的是保存在内存中的吧,过多的使用应该会造成内存不足?
内容总结
以上是互联网集市为您收集整理的关于PHP中方法中的static的问题全部内容,希望文章能够帮你解决关于PHP中方法中的static的问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。