You are here: Re: [PHP] Is there a way to get a variable name as a string? « PHP « IT news, forums, messages
Re: [PHP] Is there a way to get a variable name as a string?

Posted by Edward Vermillion on 07/22/05 15:54

Richard Lynch wrote:

[snip]

>
> PS
>
> It's true that your variable could/would/should appear in debug_backtrace,
> but how would you pick it out from all the other variables that would
> appear in your debug_backtrace?
>
> For that matter, it's in $_GLOBALS, but how would you pick it out?
>
> You could print out all variables that were equal to your variable, and
> have a list of candidates...
>
> <?php
> $x = 5;
> $y = 3;
> $z = 5;
> while (list($k, $v) = each($GLOBALS)){
> if ($v === $x) echo "$k might be your variable...<br />\n";
> }
> ?>
>

What I was thinking with debug_backtrace() is that you could get the
information for the function that called the function you want the
variable name for, *reducing* the likelyhood of duplicate values, but
admitedly not eliminating it.

You could also pass the name of the variable to the function:

someFunction($foo, $varName=""){ print $varName; }

call it with -> someFunction($bar, 'bar');

That would definately get you what you want, but again it would be messy
to look at.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация