From:             bmorel at ssi dot fr
Operating system: Fedora Core 4
PHP version:      5.0.4
PHP Bug Type:     Scripting Engine problem
Bug description:  Foreach uses the same internal pointer in different 
iterations of recursive fns

Description:
------------
Sorry if this is not a bug, but I think the behavior is not normal, even
after searching the net and this bug database.

It seems that, used inside a recursive function, foreach doesn't use
different array pointers for each iteration of the function, but uses the
same at each time. This common pointer is reseted at each foreach() call.

Reproduce code:
---------------
function recurse($doRecurse = true) {
 static $array = array(1,2);
 foreach ($array as $value) {
  echo $value . PHP_EOL;
  if ($doRecurse) recurse(false);
 }
}
recurse();

Expected result:
----------------
1
1
2
2
1
2

Actual result:
--------------
1
1
2

-- 
Edit bug report at http://bugs.php.net/?id=33713&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33713&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33713&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33713&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33713&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33713&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33713&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33713&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33713&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33713&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33713&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=33713&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=33713&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33713&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33713&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33713&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33713&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33713&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33713&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33713&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33713&r=mysqlcfg

Reply via email to