Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:29068 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53865 invoked by uid 1010); 27 Apr 2007 12:54:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 53850 invoked from network); 27 Apr 2007 12:54:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Apr 2007 12:54:18 -0000 Authentication-Results: pb1.pair.com header.from=edin@krug.dk; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=edin@krug.dk; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain krug.dk designates 82.103.137.104 as permitted sender) X-PHP-List-Original-Sender: edin@krug.dk X-Host-Fingerprint: 82.103.137.104 khaled.krug.dk Received: from [82.103.137.104] ([82.103.137.104:58219] helo=khaled.krug.dk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FE/D5-29041-772F1364 for ; Fri, 27 Apr 2007 08:54:16 -0400 Message-ID: <4631F271.3010308@krug.dk> Date: Fri, 27 Apr 2007 14:54:09 +0200 User-Agent: Thunderbird 2.0.0.0 (Windows/20070326) MIME-Version: 1.0 To: Etienne Kneuss CC: internals@lists.php.net References: <4631EE73.4050409@php.net> In-Reply-To: <4631EE73.4050409@php.net> X-Enigmail-Version: 0.95.0 OpenPGP: id=157D0FA8 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [patch] Dynamic access of static members/methods, and constants From: edin@krug.dk (Edin Kadribasic) +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: http://patches.colder.ch/Zend/dynamic-static-calls.patch?markup >