php:对象自动加载 - 值得吗?
我成功地“自动加载”对象:如果我重写 __get() 方法,我就可以创建该对象。我们看到类自动加载确实有优势。但是对象自动创建也有吗?到目前为止,我拥有该对象引用(它们都是私有的和公共的),如果我删除引用,它就会自动变为公共。另一方面,代码完成不再起作用。我想说,这强烈破坏了对象类结构(没有属性)。 那么,它方便吗?我可以用它获得更快的速度吗?
I successfully managed to "autoload" objects: if I override the __get() method, I can just create the object. We seen that class autoloading does have advantage. But does object auto creating have too? Until now I had that object references (they both were private and public) and if I remove the reference, it becomes public automatic. And the other hand, code completition doesnt work anymore. I would say, this strongly ruin the object-class structure (no property).
So, does it comes handy? Can I gain more speed with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在给定的情况下,如果您从数据库或 Web 服务或任何需要很长时间加载的对象延迟加载,则可以获得加速。然而,速度增益并非来自 __get 或 __set 方法,而是来自避免加载数据,这实际上并不是必需的。 __get 和 __set 只是为您提供更多机会的语言结构。
You can under given circumstances gain a speedup, if you lazy-load objects from a database or a webservice, or anything that takes long to load. The speedgain does however not come from the __get or __set methods, but instead from avoiding to load data, that is not actually required. __get and __set are only language constructs that give you more opportunities.