ID: 27938 User updated by: davelowe at davelowe dot net Reported By: davelowe at davelowe dot net -Status: Open +Status: Bogus Bug Type: Variables related Operating System: Windows 2000 Pro PHP Version: 4.3.5 New Comment:
Darnit, you have to: $g_userName = 'dave'; $name = 'g_userName'; $trueName = $$name; I needed to strip off the leading '$' to get my code to work, sorry about the wasted bandwidth. Previous Comments: ------------------------------------------------------------------------ [2004-04-09 22:31:08] davelowe at davelowe dot net Description: ------------ I have a column value coming back from a mysql query that is '%$g_userName' Now, when I look at the column for each row and see a leading '%', I know that the value is actually the name of a variable that exists in my application. Here's a code snippet, where $name contains the column's value as returned by mysql (the value is '%$g_userName'): if (substr($name, 0, 1) == '%') { $actualName = substr($name, 1, strlen($name) - 1); $name = $$actualName; } When the code above gets executed, I get the following error: Notice: Undefined variable: $g_userName in C:\htdocs\ebbs\scripts\rightMenu_inc.php on line 51 I added the following immediately after the if {...} to make sure $g_userName actually exists and contains a value: echo $g_userName.'<br />'; And now I get the following: Notice: Undefined variable: $g_userName in C:\htdocs\ebbs\scripts\rightMenu_inc.php on line 51 dave Where 'dave' is the value I had hard-coded in $g_userName. Reproduce code: --------------- $g_userName = 'dave'; $name = '$'.'g_userName'; $trueName = $$name; echo $trueName; Expected result: ---------------- dave Actual result: -------------- Notice: Undefined variable: $g_userName in C:\htdocs\ebbs\scripts\pageFooter_inc.php on line 7 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27938&edit=1