|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-04-09 22:35 UTC] davelowe at davelowe dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 18:00:02 2025 UTC |
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