|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-10-24 17:51 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2014-10-24 17:51 UTC] requinix@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 21:00:01 2026 UTC |
Description: ------------ This bug occurs at least on PHP 5.5.9, 5.5.16 & 5.6.0 on both gentoo and ubuntu 14.04. When 2 foreach iterate over the same array with the same variable to store the iteration value and the 1st foreach uses reference on the iteration variable but not the 2nd foreach, at the end of the 2nd foreach, the last value of the array is modified. the problem occurs: * when array values are objects or integers * only if the 1st foreach uses '&' but not the 2nd foreach * only if the 2 foreach use the same variable to store the iteration value * on both apache2 module and cli adding print_r inside the 2nd foreach shows array changes. At each iteration, the last value of the array is modified. My configuration for PHP 5.6.0 (cli) is the following: './configure' '--prefix=/usr' '--build=x86_64-pc-linux-gnu' '--host=x86_64-pc-linux-gnu' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--datadir=/usr/share' '--sysconfdir=/etc' '--localstatedir=/var/lib' '--prefix=/usr/lib64/php5.6' '--mandir=/usr/lib64/php5.6/man' '--infodir=/usr/lib64/php5.6/info' '--libdir=/usr/lib64/php5.6/lib' '--with-libdir=lib64' '--without-pear' '--enable-maintainer-zts' '--disable-bcmath' '--without-bz2' '--disable-calendar' '--enable-ctype' '--with-curl=/usr' '--enable-dom' '--without-enchant' '--disable-exif' '--enable-fileinfo' '--enable-filter' '--disable-ftp' '--with-gettext=/usr' '--without-gmp' '--enable-hash' '--without-mhash' '--with-iconv' '--disable-intl' '--disable-ipv6' '--enable-json' '--without-kerberos' '--enable-libxml' '--with-libxml-dir=/usr' '--enable-mbstring' '--with-mcrypt=/usr' '--without-mssql' '--with-onig=/usr' '--without-openssl' '--without-openssl-dir' '--enable-pcntl' '--disable-phar' '--enable-pdo' '--disable-opcache' '--without-pgsql' '--enable-posix' '--without-pspell' '--without-recode' '--enable-simplexml' '--disable-shmop' '--without-snmp' '--disable-soap' '--enable-sockets' '--without-sqlite3' '--without-sybase-ct' '--disable-sysvmsg' '--disable-sysvsem' '--disable-sysvshm' '--without-fpm-systemd' '--without-tidy' '--enable-tokenizer' '--disable-wddx' '--enable-xml' '--disable-xmlreader' '--enable-xmlwriter' '--without-xmlrpc' '--without-xsl' '--enable-zip' '--with-zlib=/usr' '--disable-debug' '--without-cdb' '--without-db4' '--disable-flatfile' '--without-gdbm' '--disable-inifile' '--without-qdbm' '--with-freetype-dir=/usr' '--with-t1lib=/usr' '--disable-gd-jis-conv' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--without-xpm-dir' '--without-vpx-dir' '--with-gd' '--with-ldap=/usr' '--without-ldap-sasl' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-mysql-sock=/var/run/mysqld/mysqld.sock' '--without-pdo-dblib' '--with-pdo-mysql=mysqlnd' '--without-pdo-pgsql' '--without-pdo-sqlite' '--without-pdo-odbc' '--without-readline' '--without-libedit' '--without-mm' '--with-pic' '--with-pcre-regex=/usr' '--with-pcre-dir=/usr' '--with-config-file-path=/etc/php/cli-php5.6' '--with-config-file-scan-dir=/etc/php/cli-php5.6/ext-active' '--disable-embed' '--enable-cli' '--disable-cgi' '--disable-fpm' '--without-apxs2' 'build_alias=x86_64-pc-linux-gnu' 'host_alias=x86_64-pc-linux-gnu' 'CFLAGS=-march=native '-O2' '-pipe'' 'LDFLAGS=-Wl,-O1 '-Wl,--as-needed'' 'CPPFLAGS=' 'CXXFLAGS=-march=native '-O2' '-pipe'' No loaded modules. No changes made on php.ini Test script: --------------- $a = array(); $a[1] = 1; $a[2] = 3; $a[3] = 5; $a[4] = 7; foreach($a as &$v) { } foreach($a as $v) { } print_r($a); Expected result: ---------------- Array ( [1] => 1 [2] => 3 [3] => 5 [4] => 7 ) Actual result: -------------- Array ( [1] => 1 [2] => 3 [3] => 5 [4] => 5 )