php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31165 foreach() strange behavior
Submitted: 2004-12-18 00:41 UTC Modified: 2004-12-18 02:18 UTC
From: abajolet at toiletoine dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.10 OS: Linux 2.6.9
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: abajolet at toiletoine dot net
New email:
PHP Version: OS:

 

 [2004-12-18 00:41 UTC] abajolet at toiletoine dot net
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-18 01:41 UTC] jed@php.net
Do not file bugs when you have Zend extensions (zend_extension=)
loaded. Examples are Zend Optimizer, Zend Debugger, Turck MM Cache,
APC, Xdebug and ionCube loader.  These extensions often modify engine
behavior which is not related to PHP itself.

Get rid of ZendOptimizer or upgrade it, and this problem will go away.
 [2004-12-18 02:18 UTC] abajolet at toiletoine dot net
Ok, sorry for false bug.
Upgraded ZendOptimizer 2.1 => 2.5 and the problem is solved.

Thanks for help
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 20:01:32 2024 UTC