php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31126 Serious Bug in foreach
Submitted: 2004-12-16 16:57 UTC Modified: 2004-12-16 17:05 UTC
From: rf at inmacom dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.10 OS: Linux
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rf at inmacom dot de
New email:
PHP Version: OS:

 

 [2004-12-16 16:57 UTC] rf at inmacom dot de
Description:
------------
Foreach gives an array instead of the value for each element of an array.


Reproduce code:
---------------
<?
$a = array( "21","22","23","24","25" );
var_dump( $a );
echo "<hr />";
foreach( $a as $v ) {
  var_dump( $v );
  echo "<hr />";
}
?>


Expected result:
----------------
array(5) {
  [0]=>
  string(2) "21"
  [1]=>
  string(2) "22"
  [2]=>
  string(2) "23"
  [3]=>
  string(2) "24"
  [4]=>
  string(2) "25"
}
<hr />string(2) "21"
<hr />string(2) "22"
<hr />string(2) "23"
<hr />string(2) "24"
<hr />string(2) "25"
<hr />

Actual result:
--------------
array(5) {
  [0]=>
  string(2) "21"
  [1]=>
  string(2) "22"
  [2]=>
  string(2) "23"
  [3]=>
  string(2) "24"
  [4]=>
  string(2) "25"
}
<hr />array(2) {
  [0]=>
  string(2) "21"
  [1]=>
  int(0)
}
<hr />array(2) {
  [0]=>
  string(2) "22"
  [1]=>
  int(1)
}
<hr />array(2) {
  [0]=>
  string(2) "23"
  [1]=>
  int(2)
}
<hr />array(2) {
  [0]=>
  string(2) "24"
  [1]=>
  int(3)
}
<hr />array(2) {
  [0]=>
  string(2) "25"
  [1]=>
  int(4)
}
<hr />

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-16 17:05 UTC] derick@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.

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 21:01:35 2025 UTC