#44258 [NEW]: Scope/function issue
| From: | stpetersn at hotmail dot com | Date: | Tue, 26 Feb 2008 22:52:17 +0000 |
| Subject: | #44258 [NEW]: Scope/function issue | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-122728@lists.php.net to get a copy of this message | ||
From: stpetersn at hotmail dot com
Operating system: Windows XP
PHP version: 5.2.5
PHP Bug Type: Variables related
Bug description: Scope/function issue
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 bug report at http://bugs.php.net/?id=44258&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44258&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44258&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44258&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44258&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=44258&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44258&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44258&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44258&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44258&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44258&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=44258&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=44258&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44258&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44258&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44258&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44258&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44258&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44258&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44258&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44258&r=mysqlcfg