Edit report at http://bugs.php.net/bug.php?id=52225&edit=1
ID: 52225 Comment by: henrik at bearwoods dot dk Reported by: lucato at gmail dot com Summary: __get() and __set() for static classes Status: Open Type: Feature/Change Request Package: Class/Object related Operating System: Any PHP Version: 5.3.2 New Comment: In 5.3 it works if you change self:: to static:: like this Test: <?php class A { static $data = array('bar' => 99, 'foo' => 101); function __get($name) { if (isset(static::$data[$name])) return static::$data[$name]; return null; } } class B extends A { } $object = new B(); print $object->foo; Result ------ 101 Previous Comments: ------------------------------------------------------------------------ [2010-07-01 19:51:00] lucato at gmail dot com Description: ------------ Would it be possible to have magic setter/getter functions available on static context ? The documentation says "Property overloading only works in object context. These magic methods will not be triggered in static context." I would find it useful on a static context where I have a class A extending another class B, to access Test script: --------------- Example: Class A { static $data = array('bar' => 99, 'foo' => 101); function __get($name) { if (isset(self::$data[$name])) return self::$data[$name]; return null; } } Class B extends A { } echo B::$foo; Expected result: ---------------- echo B::$foo; In the example should return 101. Actual result: -------------- In the example it triggers a fatal error. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52225&edit=1