#40608 [NEW]: break within foreach causes strange behaviour
| From: | eric dot broersma at phil dot uu dot nl | Date: | Fri, 23 Feb 2007 16:49:12 +0000 |
| Subject: | #40608 [NEW]: break within foreach causes strange behaviour | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-109416@lists.php.net to get a copy of this message | ||
From: eric dot broersma at phil dot uu dot nl
Operating system: Sun Solaris
PHP version: 5.2.1
PHP Bug Type: Arrays related
Bug description: break within foreach causes strange behaviour
Description:
------------
A break within a foreach construct may cause an infinite loop when the
foreach construct is nested within another foreach construct, possibly as
a result of the internal array pointer of the array being foreach'ed not
being reset.
This problem did not occur in PHP 5.0.5, but did occur in PHP 5.2.1.
Reproduce code:
---------------
$w = array ( 0, 1 );
echo 'a';
foreach ( $w as $x ) {
echo 'b' . $x;
foreach ( $w as $z ) {
echo 'c' . $z;
break 1;
}
echo 'e' . $x;
}
echo 'f';
Expected result:
----------------
ab0c0e0b1c0e1f
(Behaviour in PHP 5.0.5)
Actual result:
--------------
ab0c0e0b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1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c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b2c0e2b1c0e1b...
(infinite loop)
(Behaviour in PHP 5.2.1)
--
Edit bug report at http://bugs.php.net/?id=40608&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40608&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40608&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40608&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=40608&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=40608&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=40608&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=40608&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=40608&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=40608&r=support
Expected behavior: http://bugs.php.net/fix.php?id=40608&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=40608&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=40608&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=40608&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40608&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=40608&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=40608&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=40608&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=40608&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=40608&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=40608&r=mysqlcfg