Re: Variable variable
| From: | Rasmus Lerdorf | Date: | Wed, 18 Apr 2001 14:39:45 +0000 |
| Subject: | Re: Variable variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-49226@lists.php.net to get a copy of this message | ||
> "Rasmus Lerdorf" <rasmus@php.net> wrote:
> > > 1. If $id is a number I believe PHP will choke b/c I don't believe
> numbers
> > > can be used as variable names.
> >
> > Well, generally that is true. If you try to assign a value directly to a
> > variable that is a number such as:
> >
> > $1 = "Hello World";
> >
> > Then it won't work. However, due to a somewhat quirky implementation you
> > can get arund this by doing:
> >
> > $a=1;
> > $$a = "Hello World";
>
> Sure enough, it works. Rasmus, can we expect this behavior to exist in
> future releases of PHP? I prefer to give variables a meaningful name, but
> since I spend a fair amount of time working with other people's code and
> clients who sometimes insist on things that aren't preferable, it would be
> nice to know.
Writing code that relies on this behaviour is a bad idea. It is unlikely
to change in PHP 4, but who knows what will happen in the longer term...
-Rasmus