ID: 44258 Updated by: [EMAIL PROTECTED] Reported By: stpetersn at hotmail dot com -Status: Open +Status: Bogus Bug Type: Variables related Operating System: Windows XP PHP Version: 5.2.5 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php See http://docs.php.net/global Previous Comments: ------------------------------------------------------------------------ [2008-02-26 22:52:17] stpetersn at hotmail dot com Description: ------------ When I run this: for ($a=1;$a<10;$a++){ drawstar($a); } function drawstar($a){ $txt="*"; for ($ct=0;$ct<$a;$ct++){ echo $txt; } echo "\n"; } I get a printout of the stars. The $txt variable is local to the function. If I make $txt global scope to the entire file like below it won't work. $txt="*"; for ($a=1;$a<10;$a++){ drawstar($a); } function drawstar($a){ for ($ct=0;$ct<$a;$ct++){ echo $txt; } echo "\n"; } Expected result: ---------------- Variable defined globally should be accessible anywhere. Actual result: -------------- Nothing happens ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44258&edit=1
