[php-maint] Bug#332735: php4: foreach needs $key to work properly

Tobias Daur daur at gmx.de
Sat Oct 8 08:44:44 UTC 2005

Package: php4
Version: 4.3.10-16

Foreach in php normaly works with and without a given key:

foreach (array_expression as $value)
foreach (array_expression as $key => $value)


In the first case, without $key, foreach should behave like this:

The first form loops over the array given by array_expression. On each
loop, the value of the current element is assigned to $value

But foreach in the package mentioned above doesn't assign the value of
the current element, but the complete array. 

This is a test-script: 


$aTest = array('a' => 'aaa','b' => 'bbb','c' => 'ccc');

// this produces the correct output: aaabbbccc
foreach($aTest as $k => $v) {
	 echo $v;

// this should produce the same output, but gives back 
// ArrayArrayArray
foreach($aTest as $v) {
	echo $v;


More information about the pkg-php-maint mailing list