Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:29802 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40502 invoked by uid 1010); 26 May 2007 11:57:40 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 40486 invoked from network); 26 May 2007 11:57:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 May 2007 11:57:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=marco.kaiser@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=marco.kaiser@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 66.249.92.168 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: marco.kaiser@gmail.com X-Host-Fingerprint: 66.249.92.168 ug-out-1314.google.com Linux 2.4/2.6 Received: from [66.249.92.168] ([66.249.92.168:64628] helo=ug-out-1314.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B1/C0-31507-3B028564 for ; Sat, 26 May 2007 07:57:39 -0400 Received: by ug-out-1314.google.com with SMTP id m2so1003719uge for ; Sat, 26 May 2007 04:57:37 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=pgJIZqTlvjB7B+DiamLm8jzVxuhu5H/wT8jr0RBHRNZX2AFEa33PjY162i9hLSHkgnqrUyykcYA8G91JuLsqC3y5Y7jQNm5QLKAFJKMxM5Mmqo0M9lwkkLOb38D446sH9WMkdD4hmrUOVWYIOvMqgioMreoO5GnstT6+XcOtE+E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=i93kwExvLoEGh8sRyPfyzdfeO/oYqwthdRqPWm2ZFZkRH40q2qci9g2ffSJVzzIybnv2DanYgXDvMuWzSonrRx8Spyf5oKNTSzYu2F+MlcrZyej2hJXE8567ia76NOTpI0X/9rUMFaDLTxDMCYRf4TnjSq6+y9GHWXExf7EMmmE= Received: by 10.82.177.3 with SMTP id z3mr7349217bue.1180180655892; Sat, 26 May 2007 04:57:35 -0700 (PDT) Received: from ?10.10.4.1? ( [217.7.237.75]) by mx.google.com with ESMTP id i5sm18259912mue.2007.05.26.04.57.34; Sat, 26 May 2007 04:57:34 -0700 (PDT) Message-ID: <465820AB.7030102@gmail.com> Date: Sat, 26 May 2007 13:57:31 +0200 User-Agent: Thunderbird 2.0.0.0 (Windows/20070326) MIME-Version: 1.0 To: Bart de Boer CC: internals@lists.php.net References: <2C.70.31507.8DE18564@pb1.pair.com> In-Reply-To: <2C.70.31507.8DE18564@pb1.pair.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] $var::$static From: marco.kaiser@gmail.com (Marco Kaiser) Hi, this doesnt work because static vars are bound to his class and are not inherited by a child class. maybe this would be work with php6 or a other 5.x version. (Same behavior like the singleton pattern getInstance() abstract class stuff) -- Marco > Hi all, > > I'd like to be able to do the following: > > > > class Base { > > public static $var = 'hello'; > > public function someFunc() { > echo self::$var; // Currently maps to Base::$var > echo $this::$var; // Should map to Child::$var > } > > } > > class Child extends Base { > > public static $var = 'hello'; > > } > > $class = 'Child'; > > $obj = new $class(); // This works. > > echo $class::$var; // This doesn't. Should map to Child::$var > > > ?> > > > ...in other words: I'd like to be able to access static class > variables from inside an instance of the Base and/or Child classes. > I'd also like to be able to access them dynamically. > ($className::$variable) > > The only way to do this at the moment (to my knowledge at least) is to > create functions in the Child class that returns its static variables. > The downside of this is that those functions most likely will be very > common (in my case they are) and should therefore belong in the base > class. Hence: $this::$variable > > At the moment there is no way to access static variables from outside > of the class dynamically. As a workaround for this I'm currently > creating a temporary instance (new $type()) to access them dynamically > with a __get() function in all the derived child classes. > > There are ways to do it with class constants and the constant > functions. But it's not very elegant and class constants can't hold > arrays and/or objects. > > I have no idea what the implications would be. Just thought it would > be a nice addition to the language. :) Hope I didn't overlook some > existing PHP feature that already allows me to do this. :| > > > Cheers, > > Bart de Boer >