Req #28919 [Com]: foreach does not take list() as argument output

From: Date: Tue, 11 May 2010 15:39:51 +0000
Subject: Req #28919 [Com]: foreach does not take list() as argument output
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-150340@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=28919&edit=1

 ID:               28919
 Comment by:       rc at opelgt dot org
 Reported by:      black at scene-si dot org
 Summary:          foreach does not take list() as argument output
 Status:           Open
 Type:             Feature/Change Request
 Package:          Feature/Change Request
 Operating System: any
 PHP Version:      Irrelevant

 New Comment:

Why not using this code?

foreach ($table as $key=>$val) {
  echo $key.":".$val[0].", ".$val[1]."\n";
}


Previous Comments:
------------------------------------------------------------------------
[2004-06-25 19:48:45] pollita@php.net

This is expected behavior.  list() is a left-hand language construct and
not currently intended to be used this way.

Reclassifying to Feature/Change Request.

------------------------------------------------------------------------
[2004-06-25 13:20:05] black at scene-si dot org

Description:
------------
Requesting additional functionality for foreach?

Reproduce code:
---------------
$table = array();
$table['username'] = array(1,"John doe");
$table['black'] = array(2,"Jane doe");
$table['yawn'] = array(3,"Undefined");

foreach ($table as $key=>list($id,$title)) {
  echo $key.":".$id.", ".$title."\n";
}
foreach ($table as list($id,$title)) {
  echo $id.", ".$title."\n";
}

Expected result:
----------------
username:1, John doe
black:2, Jane doe
yawn:3, Undefined
1, John doe
2, Jane doe
3, Undefined

Actual result:
--------------
Parse error


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



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


Thread (5 messages)

« previous php.bugs (#150340) next »