note 108393 rejected from language.variables.scope by salathe
| From: | salathe@php.net | Date: | Mon, 23 Apr 2012 13:12:40 +0000 |
| Subject: | note 108393 rejected from language.variables.scope by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187298@lists.php.net to get a copy of this message | ||
Note Submitter: mike at out dot there dot co dot uk
----
If I want to use a global array within a nested function, I need to do this:
$myRay = array();
$global myRay;
doTLA();
function doTLA(){
doDetail();
}
function doDetail(){
global $myRay;
...use $myRay[] contents....
}
The above works. I just spent all afternoon: Aaaargh! Maybe this'll help someone else.
It didn't work until I made the top-level declaration global.
And BTW:
global $myRay = array(); # is a syntax error
From my reading of the manual, I shouldn't need to make the top-level declaration explicitly
global, but I did. Maybe its because I'm in a nested function. Maybe there is an R in the
month.
And now someone much smarter than me can come along and point out where in TFM I missed the
explanation.