note 108393 added to language.variables.scope
| From: | mike at out dot there dot co dot uk | Date: | Sun, 22 Apr 2012 18:18:21 +0000 |
| Subject: | note 108393 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187287@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 80.103.5.170
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/108393
Del: integrated -- https://master.php.net/note/delete/108393/integrated
Del: useless -- https://master.php.net/note/delete/108393/useless
Del: bad code -- https://master.php.net/note/delete/108393/bad+code
Del: spam -- https://master.php.net/note/delete/108393/spam
Del: non-english -- https://master.php.net/note/delete/108393/non-english
Del: in docs -- https://master.php.net/note/delete/108393/in+docs
Del: other reasons-- https://master.php.net/note/delete/108393
Reject -- https://master.php.net/note/reject/108393
Search -- https://master.php.net/manage/user-notes.php