From: abajolet at toiletoine dot net
Operating system: Linux 2.6.9
PHP version: 4.3.10
PHP Bug Type: Arrays related
Bug description: foreach() strange behavior
Description:
------------
Hello,
between php 4.3.9 and php 4.3.10, foreach() changes its behavior (see code
below).
The ./configure and linked libraries are exactly the same in the two
versions :
'./configure' '--with-apxs2=/usr/local/apache2/bin/apxs'
'--with-config-file-path=/etc' '--with-ming' '--with-ldap' '--with-mysql'
'--with-pgsql' '--with-gd' '--with-jpeg-dir=../jpeg-6b'
'--with-png-dir=../libpng-1.2.2' '--with-freetype-dir=../freetype-2.1.7'
'--with-t1lib' '--enable-bcmath' '--enable-calendar' '--enable-trans-sid'
'--with-mcrypt' '--with-mhash' '--with-regex=php' '--with-zlib'
'--enable-ftp' '--with-snmp' '--with-openssl=/usr/local/ssl'
'--enable-sockets' '--enable-track-vars' '--enable-magic-quotes'
'--enable-xslt' '--with-xslt-sablot' '--with-iconv=/usr/local'
'--enable-sigchild' '--enable-inline-optimization'
'--with-mm=/usr/local/mm' '--enable-sysvsem' '--enable-sysvshm'
'--enable-sysvmsg' '--enable-pcntl'
Regards,
Antoine Bajolet
Reproduce code:
---------------
<?php
print phpversion() . '<br/>';
$array['foo'] = array('one'=>'two',
'three'=>'for');
$array['bar'] = array('five'=>'six',
'seven'=>'eight');
print_r($array); print '<br/>';
foreach ($array as $sub){
foreach($sub as $key => $value) {
print $key . '=>' .$value .'<br/>';
}
}
?>
Expected result:
----------------
4.3.9
Array ( [foo] => Array ( [one] => two [three] => for ) [bar] => Array (
[five] => six [seven] => eight ) )
one=>two
three=>for
five=>six
seven=>eight
Actual result:
--------------
4.3.10
Array ( [foo] => Array ( [one] => two [three] => for ) [bar] => Array (
[five] => six [seven] => eight ) )
0=>Array
1=>foo
0=>Array
1=>bar
--
Edit bug report at http://bugs.php.net/?id=31165&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31165&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=31165&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=31165&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31165&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31165&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31165&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31165&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31165&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31165&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31165&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=31165&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=31165&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31165&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31165&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31165&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31165&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31165&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31165&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31165&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31165&r=mysqlcfg