From: hannes dot magnusson at gmail dot com
Operating system: Linux/Ubuntu 7.04
PHP version: 5CVS-2007-08-15 (CVS)
PHP Bug Type: Arrays related
Bug description: Using current/next/prev/key on the same array as foreach() is
currently looping
Description:
------------
If I use current/next/prev/key() on the same array as foreach() is
currently looping over the internal pointer is only increased on the first
iteration.
However. If I compare the value ($b) to something before using
current/next/prev/key() I get the expected results:
$a = range(0, 10);
foreach($a as $b) {
if($b == 5) {
var_dump(current($a)); // int(6)
}
}
Reproduce code:
---------------
<?php
$a = range(0, 10);
foreach($a as $b) {
var_dump(current($a));
if($b == 5) {
var_dump(current($a));
}
}
Expected result:
----------------
int(1)
int(2)
int(3)
int(4)
int(5)
int(6) // The var_dump() inside the if()
int(6)
int(7)
int(8)
int(9)
int(10)
bool(false) // Since the internal pointer points beyond the end
Actual result:
--------------
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
--
Edit bug report at http://bugs.php.net/?id=42306&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=42306&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=42306&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=42306&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=42306&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=42306&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=42306&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=42306&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=42306&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=42306&r=support
Expected behavior: http://bugs.php.net/fix.php?id=42306&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=42306&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=42306&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=42306&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42306&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=42306&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=42306&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=42306&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=42306&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=42306&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=42306&r=mysqlcfg