treznik treznik - 3 months ago 16x
PHP Question

Magic __get getter for static properties in PHP

public static function __get($value)

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?


No, it is not possible.

Quoting the manual page of __get :

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.

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.

There is even a Request for Comments: Static classes for PHP
But, still, not implemented (yet ? )