php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30496 foreach wrong assignment with multidim arrays
Submitted: 2004-10-20 15:17 UTC Modified: 2004-10-21 09:20 UTC
From: esartoni at omniaglobal dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4CVS-2004-10-20 (stable) OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: esartoni at omniaglobal dot net
New email:
PHP Version: OS:

 

 [2004-10-20 15:17 UTC] esartoni at omniaglobal dot net
Description:
------------
foreach doesn't work as expected when using multidimensional arrays.

Reproduce code:
---------------
<?php
	$a=array();
	$a[]=array("one", "two", "three");
	$a[]=array("five", "six", "seven");
	
	// Code 1 (THIS DON'T WORK AS EXPECTED)
	foreach ($a as $value) {
		echo join(",", $value)."\n";
	}
/*
  This code below is a workaround:

        // Code 2 (THIS WORKS!)
	foreach ($a as $key => $value) {
		echo join(",", $value)."\n";
	}
*/
?>

Expected result:
----------------
one,two,three
five,six,seven

Actual result:
--------------
Array,0
Array,1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-20 15:19 UTC] esartoni at omniaglobal dot net
With PHP v4.3.9 works ok!
 [2004-10-20 15:34 UTC] derick@php.net
Works fine here.
 [2004-10-20 16:00 UTC] esartoni at omniaglobal dot net
I'm sorry derick but here with v4.3.10-dev doesn't work!

I've also tried with Solaris (SPARC) with same results.
 [2004-10-20 17:58 UTC] mserra at consrav dot net
$a=array(1,2,3,4,5);
foreach($a as $value) {
  echo $value."\n";
}

OUTPUT:
Array
Array
Array
Array
Array

EXPECTED:
1
2
3
4
5
 [2004-10-20 18:10 UTC] tony2001@php.net
Works fine with latest snapshot (and other versions too).
 [2004-10-20 18:25 UTC] esartoni at omniaglobal dot net
I've found the problem. The bug appears only when using Zend Optimizer v2.5.5
Disabling the optimizer makes the code working.

P.S.: This bug report is not bogus. :) Zend Optimizer is bogus!
 [2004-10-21 08:56 UTC] esartoni at omniaglobal dot net
Try with Zend Optimizer 2.5.5 and let me know please. The bug is always there with php 4.3.10-dev.
 [2004-10-21 09:20 UTC] derick@php.net
Report Zend optimizer related problems to the Zend people, this is not a bug in PHP so we mark it as bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 16:01:30 2024 UTC