[patch] Dynamic access of static members/methods, and constants
| From: | Etienne Kneuss | Date: | Fri, 27 Apr 2007 12:37:07 +0000 |
| Subject: | [patch] Dynamic access of static members/methods, and constants | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-29067@lists.php.net to get a copy of this message | ||
Hi,
I've already proposed that 1-2 months ago, but now seems to be a good
time to discuss new things, so let's try again:
I believe it would be nice to be able to dynamically reference static
members, constants, and methods.
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 = 'value1';
const gee = 'value2';
public static function bar() { return 'value3'; }
// old way:
public static function getFoo() { return self::$foo; }
public static function getGee() { return self::gee; }
}
$classname = 'A';
echo $classname::$foo; // value1
echo $classname::gee; // value2
echo $classname::bar(); // value3
// --- instead of: ---
$classname = 'A';
echo call_user_func(array($classname, 'getFoo')); // value1
echo call_user_func(array($classname, 'getGee')); // value2
echo call_user_func(array($classname, 'bar')); // value3
which is quite slow.
Please take a look at the patch[1] I made for it. Comments would be
appreciated!
Regards,
1: http://patches.colder.ch/Zend/dynamic-static-calls.patch?markup
--
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