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

From: Date: Fri, 27 Apr 2007 12:54:09 +0000
Subject: Re: [patch] Dynamic access of static members/methods, and constants
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-29068@lists.php.net to get a copy of this message
+1 Nice to be able to do this directly without resorting to call_user_func(). Edom Etienne Kneuss wrote: > 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: JdîÞJ > 0ÓÁ)€Gϯhttp://patches.colder.ch/Zend/dynamic-static-calls.patch?markup >

« previous php.internals (#29068) next »