From:             davelowe at davelowe dot net
Operating system: Windows 2000 Pro
PHP version:      4.3.5
PHP Bug Type:     Variables related
Bug description:  Variable variable causing undefined variable error

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 bug report at http://bugs.php.net/?id=27938&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27938&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27938&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27938&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27938&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27938&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27938&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27938&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27938&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27938&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27938&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27938&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27938&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27938&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27938&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27938&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27938&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27938&r=float

Reply via email to