dynamic variable name

This is a discussion on dynamic variable name within the PHP Language forums, part of the PHP Programming Forums category; I have no clue if this can be done, but I thought I'd ask anyway. I have a modular ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-05-2006
paladin.rithe@gmail.com
 
Posts: n/a
Default dynamic variable name

I have no clue if this can be done, but I thought I'd ask anyway. I
have a modular system where I store module information in a database.
One of the types of modules that I have is one that, depending on the
file, could have a different variable name in each file. I have named
the module, and want to name it according to the name of the variable
(ie, modulename Joe, var $Joe) Now, this variable needs to be loaded
into a function, but not inside the file it's located. That file is
basicly a storage for it, and the variable is needed elsewhere. Is
there a way to use the modulename (Joe), and convert it to the variable
name? (func($Joe) in other words)
Another way I could do it is to just have a function that returns the
variable. That would probably be easier.
Is there a way to do this, or is it too complicated? Just using a
function to return a value would be easy.

Reply With Quote
  #2 (permalink)  
Old 03-05-2006
Oli Filth
 
Posts: n/a
Default Re: dynamic variable name

paladin.rithe@gmail.com said the following on 05/03/2006 13:29:
> I have no clue if this can be done, but I thought I'd ask anyway. I
> have a modular system where I store module information in a database.
> One of the types of modules that I have is one that, depending on the
> file, could have a different variable name in each file. I have named
> the module, and want to name it according to the name of the variable
> (ie, modulename Joe, var $Joe) Now, this variable needs to be loaded
> into a function, but not inside the file it's located. That file is
> basicly a storage for it, and the variable is needed elsewhere. Is
> there a way to use the modulename (Joe), and convert it to the variable
> name? (func($Joe) in other words)
> Another way I could do it is to just have a function that returns the
> variable. That would probably be easier.
> Is there a way to do this, or is it too complicated? Just using a
> function to return a value would be easy.
>


You can get the variable from a string, e.g.:

$joe = 666;
$name = "joe";
echo $$name;


However, programmatically, creating a function that returns the variable
is much more sensible. It would be even more sensible to just have the
variable named the same in every file (what's the advantage in having it
named differently in each file?).


--
Oli
Reply With Quote
  #3 (permalink)  
Old 03-05-2006
paladin.rithe@gmail.com
 
Posts: n/a
Default Re: dynamic variable name

I guess there really isn't any advantage to having different variable
names. I'll probably go with the function route though. That will
allow me to do a bit more with it if need be. Thanks though. If I
need that in the future, then I'll know how to do it.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:58 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0