#44258 [Opn->Bgs]: Scope/function issue

From: Date: Tue, 26 Feb 2008 22:56:56 +0000
Subject: #44258 [Opn->Bgs]: Scope/function issue
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-122729@lists.php.net to get a copy of this message
 ID:               44258
 Updated by:       felipe@php.net
 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


Thread (2 messages)

« previous php.bugs (#122729) next »