Bug #68595 [Fbk->NoF]: variable variables scope problem in for loops

From: Date: Sun, 04 Jan 2015 04:22:14 +0000
Subject: Bug #68595 [Fbk->NoF]: variable variables scope problem in for loops
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189636@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68595&edit=1 ID: 68595 Updated by: php-bugs@lists.php.net Reported by: jmichae3 at yahoo dot com Summary: variable variables scope problem in for loops -Status: Feedback +Status: No Feedback Type: Bug Package: Scripting Engine problem Operating System: windows 7 sp1 x64 PHP Version: 5.5.19 Private report: N New Comment: No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. Previous Comments: ------------------------------------------------------------------------ [2014-12-23 19:06:21] ab@php.net @jmichae3 at yahoo dot com, you can do that. Leave only one variable, remove the strtoupper() loop, remove peak usage check, etc. Please leave only what is relevant to the matter you report. Thanks. ------------------------------------------------------------------------ [2014-12-13 16:02:21] jmichae3 at yahoo dot com 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. ------------------------------------------------------------------------ [2014-12-12 19:20:46] aharvey@php.net What do you mean by "doesn't work"? Can you reduce this to a minimal, runnable example, please? Note that PHP doesn't have block scope, so any loops are within the same scope as the function as a whole. ------------------------------------------------------------------------ [2014-12-12 15:20:58] jmichae3 at yahoo dot com workaround is to avoid curly braces in th efor loops altogether and nest for loops and use 2 source arrays: http://pastebin.com/RMuqU3AF ------------------------------------------------------------------------ [2014-12-12 15:03:58] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68595&edit=1

« previous php.bugs (#189636) next »