PHP中静态属性的魔术__get getter [英] Magic __get getter for static properties in PHP
问题描述
public static function __get($value)
不起作用,即使它起作用了,碰巧我已经需要神奇的 __get getter 用于同一类中的实例属性.
does not work, and even if it did, it so happens that I already need the magic __get getter for instance properties in the same class.
这可能是一个是或否的问题,所以,有可能吗?
This probably is a yes or no question, so, it is possible?
推荐答案
不,这是不可能的.
成员重载仅适用于对象上下文.这些神奇的方法不会被静态触发语境.因此这些方法可以不得声明为静态.
Member overloading only works in object context. These magic methods will not be triggered in static context. Therefore these methods can not be declared static.
在 PHP 5.3 中,__callStatic
已添加;但是还没有 __getStatic
和 __setStatic
;即使拥有/编码它们的想法经常出现在 php internals@ mailling-list 上.
In PHP 5.3, __callStatic
has been added ; but there is no __getStatic
nor __setStatic
yet ; even if the idea of having/coding them often comes back on the php internals@ mailling-list.
甚至还有一个征求意见:PHP 的静态类
但是,仍然没有实现(还没有?)
这篇关于PHP中静态属性的魔术__get getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!