Bug #68595 [NEW]: variable variables scope problem in for loops
| From: | jmichae3 at yahoo dot com | Date: | Fri, 12 Dec 2014 15:03:59 +0000 |
| Subject: | Bug #68595 [NEW]: variable variables scope problem in for loops | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-189034@lists.php.net to get a copy of this message | ||
From: jmichae3 at yahoo dot com
Operating system: windows 7 sp1 x64
PHP version: 5.5.19
Package: Scripting Engine problem
Bug Type: Bug
Bug description:variable variables scope problem in for loops
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 bug report at https://bugs.php.net/bug.php?id=68595&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68595&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68595&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68595&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68595&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68595&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68595&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68595&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68595&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68595&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68595&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68595&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68595&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68595&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68595&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68595&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68595&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68595&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68595&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68595&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68595&r=mysqlcfg