Magic __get getter for static properties in PHP

treznik picture treznik · Aug 14, 2009 · Viewed 34.8k times · Source
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?

Answer

Pascal MARTIN picture Pascal MARTIN · Aug 14, 2009

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 ? )