RE: [PHP] variable names
| From: | Lawrence dot Sheed at dfait-maeci dot gc dot ca | Date: | Wed, 15 Nov 2000 05:51:34 +0000 |
| Subject: | RE: [PHP] variable names | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-25369@lists.php.net to get a copy of this message | ||
Try this:
function show($var_name)
{
global $$var_name;
printf("$%s=\"%s\"", $var_name, $$var_name);
return 1;
}
-----Original Message-----
From: Jan-Eric Duden [mailto:duden@uwyo.edu]
Sent: November 15, 2000 07:26 AM
To: Lars Torben Wilson
Cc: php-general@lists.php.net
Subject: Re: [PHP] variable names
Hi!
oops ... :)
You're right ... my wanted feature is very difficult to implement ...
- even saying which varname i really want is difficult
i'll think about an work around ...
Eric
----- Original Message -----
From: "Lars Torben Wilson" <torben@pinc.com>
To: "Jan-Eric Duden" <jeduden@whisset.com>
Cc: <php-general@lists.php.net>
Sent: Tuesday, November 14, 2000 5:12 PM
Subject: Re: [PHP] variable names
> Jan-Eric Duden writes:
> > Hi!
> >
> > Does anybody know if there is a function that returns the name of
variable?
> > I imagine something like this:
> >
> > $myvar="bla";
> > $name=GetVarName($myvar);
> >
> > $name=="myvar"
> >
> > Thks
> > Eric
>
> No. A given variable can have several names; which one do you want?
> For instance:
>
> <?php
> $foo = 'Bob';
> $bar = &$foo;
> $baz = &$foo;
>
> $name = getvarname($baz);
>
> echo $name; // what should the output be?
> ?>
>
> In the above code, we end up with three names for the same slot in the
> symbol table: $foo, $bar, and $baz are all different names for the
> same value in memory. So should getvarname() return 'baz' in the above
> case? If so, the you have to have known the name to write the function
> call to start with.
>
> You may be able to emulate the effect you're after using variable
> variables; that way, you can just use a string variable as the
> variable name:
>
> <?php
> $varname = 'foo';
> $$varname = 'Bob';
> echo "$varname == $foo\n";
> ?>
>
> ...which will output 'foo == Bob'. AFAIK that's about as close as you
> can get, though.
>
>
>
> --
> +----------------------------------------------------------------+
> |Torben Wilson <torben@php.net> Netmill iTech|
> |http://www.coastnet.com/~torben
> http://www.netmill.fi|
> |Ph: 1 250 383-9735 torben@netmill.fi|
> +----------------------------------------------------------------+
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net