list() inside a foreach()

From: Date: Thu, 09 May 2013 16:39:03 +0000
Subject: list() inside a foreach()
Groups: php.internals 
Request: Send a blank email to internals+get-67376@lists.php.net to get a copy of this message
Hi, trying out the following source I was astonished to see that using list() does not work directly in a foreach() but works fine if used through a temporary variable. Would allowing using list() inside the foreach()-statement be desired behaviour? Or is it just me? :-) $a = array( array(5, 'A'), array(3, 'B'), ); foreach($a as list($k, $v)) { echo $k; } Expected output: 53 Result: syntax error, unexpected 'list' (T_LIST) in ... Works: foreach($a as $b) { list($k, $v) = $b; echo $k; } Kind regards, Stefan

« previous php.internals (#67376) next »