Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:29805 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75513 invoked by uid 1010); 26 May 2007 13:37:00 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 75495 invoked from network); 26 May 2007 13:37:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 May 2007 13:37:00 -0000 Authentication-Results: pb1.pair.com smtp.mail=info@adaniels.nl; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=info@adaniels.nl; sender-id=unknown Received-SPF: error (pb1.pair.com: domain adaniels.nl from 82.94.236.173 cause and error) X-PHP-List-Original-Sender: info@adaniels.nl X-Host-Fingerprint: 82.94.236.173 loco.helderhosting.nl Linux 2.5 (sometimes 2.4) (4) Received: from [82.94.236.173] ([82.94.236.173:35293] helo=loco.helderhosting.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C2/31-61477-9F738564 for ; Sat, 26 May 2007 09:36:59 -0400 Received: from [192.168.1.170] (a80-126-54-132.adsl.xs4all.nl [80.126.54.132]) by loco (Postfix) with ESMTP id 364E010D820D; Sat, 26 May 2007 15:36:55 +0200 (CEST) Message-ID: <465837F7.1000401@adaniels.nl> Date: Sat, 26 May 2007 15:36:55 +0200 User-Agent: Thunderbird 1.5.0.10 (X11/20070403) MIME-Version: 1.0 To: Bart de Boer , internals@lists.php.net References: <2C.70.31507.8DE18564@pb1.pair.com> <465820AB.7030102@gmail.com> <465829C0.8060008@mediawave.nl> In-Reply-To: <465829C0.8060008@mediawave.nl> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] $var::$static From: info@adaniels.nl (Arnold Daniels) Hi, I agree that $this::$var isn't really logical, since $this is an object and not a class name. But I do not see why $class::$var shouldn't work, or $class::$method() for that method. You can also do $function(). Also I want to suggest that brackets can be used more freely. Currently you can use ${$group . '_myvar'}, but you can't do the same for functions and classes. It would be great if you could use {$group . '_' . $fn}() and {get_class($this)}::$var. The way to solve this problems right now is to use eval('return ' . get_class($this) . '::$var;') for getting the value. Getting a reference to the variable to set it, is even more messy. You need to do something like eval('$cvar =& ' . get_class($this) . '::$var;'); $cvar = 'bye';. Anyway, it is not so nice, but doable in user space fairly easily. So I don't see why anything needs to be added in PHP 5. It would be nice to have a better method in PHP 6 though. From Holland with love, Arnold Bart de Boer wrote: > > I seem to have been a bit too hasty with my previous reply... You > meant it wouldn't be able to access the static vars of the inherited > Base class?... I think that's a different feature regarding the static > access mechanism currently already in place... I'm only suggesting the > ability to reference classes dynamically some way... > > -- Bart > > > Marco Kaiser wrote: >> 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 >>> > >> 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 >>> >