Req #51797 [Csd->Bgs]: valid arguments for foreach

From: Date: Wed, 12 May 2010 06:14:20 +0000
Subject: Req #51797 [Csd->Bgs]: valid arguments for foreach
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-150360@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51797&edit=1

 ID:          51797
 Updated by:  mike@php.net
 Reported by: rc at opelgt dot org
 Summary:     valid arguments for foreach
-Status:      Closed
+Status:      Bogus
 Type:        Feature/Change Request
 Package:     *General Issues
 PHP Version: 5.2.13
 Assigned To: mike



Previous Comments:
------------------------------------------------------------------------
[2010-05-11 22:51:41] dtajchreber@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

The syntax you provided works just fine and doesn't emit a warning if
$array[$i] is an array... for example:

$array[2] = range(5, 10); 
$i = 2; 
foreach($array[$i] as $key => $val) echo $key . '->' . $val . PHP_EOL;

------------------------------------------------------------------------
[2010-05-11 22:39:31] degeberg@php.net

The following script works fine for me:

<?php
$array = array(
	array('foo','bar'),
	array('test','hello'),
);

$i = 0;
foreach ($array[$i] as $key => $val) {
	echo $key . $val;
}
?>

You'll have to provide a complete script that gives unexpected/incorrect

warnings.

------------------------------------------------------------------------
[2010-05-11 18:25:31] rc at opelgt dot org

Description:
------------
When I give an array to loop through the name of the array and if the
array given 
is with a key, in this case $i, should make no difference.

PHP4 didnt make a warning, PHP5 instead does.

Test script:
---------------
foreach($array[$i] as $key => $val) results in an warning message.





------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51797&edit=1


Thread (5 messages)

« previous php.bugs (#150360) next »