note 11748 deleted from language.variables.variable by irc-html
| From: | irc-html@php.net | Date: | Sat, 19 Jan 2002 18:56:33 +0000 |
| Subject: | note 11748 deleted from language.variables.variable by irc-html | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-25210@lists.php.net to get a copy of this message | ||
I was attempting to use a variable that is established outside of any function, this variable is
named using the value of a field in an array, and the array is already redefined within the
function.
<BR>Using the following command in a function yields a syntax error:
<BR>global ${$myarray["myfield"]};
<BR>{}'s seem to be the problem, as removing them, leaving the more ambiguous form of the
command works:
<BR>global $$myarray["myfield"];
<BR>To keep the variable variable from being ambiguous, define it before using it in a global
command:
<BR>$variable_name = $myarray["myfield"];
global $$variable_name;
<BR>This is also a problem when using variable variables to extend variable names, such as:
<BR>global ${extention_$variable};
<BR>Again, the best solution is to define it first:
<BR>$extended_variable .= "extention_";
$extended_variable .= $myarray["myfield"];
global $$extended_variable;
<BR>I don't know whether it brings up the syntax error in all situations or setups, but
if you are getting such an error, hopefully this will help.