[patch] Dynamic access of static members/methods, and constants

From: Date: Tue, 06 Mar 2007 15:06:55 +0000
Subject: [patch] Dynamic access of static members/methods, and constants
Groups: php.internals 
Request: Send a blank email to internals+get-28276@lists.php.net to get a copy of this message
Hi, It may have already been proposed, but I give it a shot: I believe it would be nice to be able to dynamically reference static members and constants. Currently, there is no way to do that and the only way would be to create a static method and use call_user_func(array($classname, 'getThat')); In other words: class A { public static $foo = 'bar'; const gee = 'zzz'; public static function getFoo() { return self::$foo; } } $classname = 'A'; echo $classname::$foo; // bar echo $classname::gee; // zzz // instead of: echo call_user_func(array($classname, 'getFoo')); Please take a look at the patch I made for it. For consistency purposes, I also implemented $classname::myMethod(); even if it's not required. FWIW, I've no strong feeling about it. Regards, -- Etienne Kneuss http://www.colder.ch colder@php.net Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal

« previous php.internals (#28276) next »