Re: $var::$static
| From: | Arnold Daniels | Date: | Sat, 26 May 2007 18:43:44 +0000 |
| Subject: | Re: $var::$static | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-29815@lists.php.net to get a copy of this message | ||
Hi again,
I'm aware that you can do
$a = $group . '_' . $fn; $a();, but you can do $b = $group . '_' . $var; echo $$b; as well as `echo ${$group . '_' . $var}`. It's a mater of style, not if there is any way to get it done.
Yes I've read about 'static::' some time ago, but forgot about it. Thanks for pointing it out. I (unfortunately) took that as an example, but it wasn't the case I wanted to make.
To my opinion, the ease with which you can use output of an expression to be used as name of a variable is wonderful. The code is so much clearer than when you have to create all kind of temporary variables and/or use eval. I think it is unfortunate that the same logic isn't available for functions and classes.
Best regards,
Arnold
Gregory Beaver wrote:
Arnold Daniels wrote: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, ArnoldHi Arnold, <?php $a = $group . '_' . $fn; $a(); ?> As for get_class($this)::$var it pays to search the mailing list archives. the static:: keyword is being using in PHP 6 to do exactly what you want from within a class. Outside of a class, $var::$value doesn't work yet, but the implementation of static may make it possible to implement $var::$value as well. Greg P.S. The list archives are http://marc.info/?l=php-dev and are searchable