|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-12-12 15:03 UTC] jmichae3 at yahoo dot com
Description:
------------
global keyword doesn't work in for loops because of scope issues I guess. causes a problem with my code, which wants to generate a collection of variable variables. I must manual,ly declare them all rather than iterating through the loop. the variable variables generated for stats are:
$VISITORfilecount
$VISITORfoldercount
$VISITORhttpcount
$ADMINfilecount
$ADMINfoldercount
$ADMINhttpcount
$PAIDWEBAPPSfilecount
$PAIDWEBAPPSfoldercount
$PAIDWEBAPPShttpcount
...
you COULD generate them using a nested for loop, which might be next. theoretically. but it doesn't work practically. because of scope problems, code fails in the Report() function and variable is invisible unless you have the line
global ${'VISITORfilecount'};
in the code (as in the example), normally this would not be in my code, because the list of VISITOR... changes with the web sites I configure for in the config file in which this resides - manually globalling is unnecessary.
Test script:
---------------
http://pastebin.com/vbr3TAq6
Expected result:
----------------
December 12, 2014
ADMINfoldercount=0
ADMINhttpcount=0
ADMINfilecount=0
PAIDBLSfoldercount=0
PAIDBLShttpcount=0
PAIDBLSfilecount=0
PAIDMUSICfoldercount=0
PAIDMUSIChttpcount=0
PAIDMUSICfilecount=0
PAIDWEBAPPSfoldercount=0
PAIDWEBAPPShttpcount=0
PAIDWEBAPPSfilecount=0
VISITORfoldercount=0
VISITORhttpcount=0
VISITORfilecount=1
skipped file count:
total file count: 1
total folder count: 0
total count including http: 1
Peak Ram Usage: 364488
Total Filesize in menu tree: 0
RAM/Filesize ratio:20.089731576917
Actual result:
--------------
without the manual global line:
December 12, 2014
ADMINfoldercount=0
ADMINhttpcount=0
ADMINfilecount=0
PAIDBLSfoldercount=0
PAIDBLShttpcount=0
PAIDBLSfilecount=0
PAIDMUSICfoldercount=0
PAIDMUSIChttpcount=0
PAIDMUSICfilecount=0
PAIDWEBAPPSfoldercount=0
PAIDWEBAPPShttpcount=0
PAIDWEBAPPSfilecount=0
VISITORfoldercount=0
VISITORhttpcount=0
VISITORfilecount=0
skipped file count:
total file count: 0
total folder count: 0
total count including http: 0
Peak Ram Usage: 364488
Total Filesize in menu tree: 0
RAM/Filesize ratio:20.089731576917
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 14:00:01 2025 UTC |
that *is* reduced. the source program is large and has several related files. I knew someone was going to say that, so I reduced it, but I didn't think someone was going to ask for further reduction. sorry, can't be done. the for statement's {} apparently DO have scope. once I put the global statement in {} it doesn't work.