From: Operating system: PHP version: Irrelevant Package: Scripting Engine problem Bug Type: Feature/Change Request Bug description:Assigning to list(); list() as an lvalue
Description: ------------ When an array is "assigned" to a list($of,$variables), the elements of the array are extracted and assigned to the listed variables; elements can be skipped by duplicating commas in the list(). The variables in the list() construct may themselves be list() constructs, allowing the extraction of values from nested arrays (the nesting of the list()s reflects the nesting of the arrays). On the PHP6 TODO list is the job of allowing list() to appear as the iterated value in a foreach statement (foreach($array as $key=>list($v1,$v2)){...}). My suggestion is that another place where list() might play a role is in function declarations; when a function parameter is in a list(), the argument it gets when it's called has its elements extracted and assigned to the variables in the list (see the test script for this to be clearer). If the argument is not an array, the behaviour would be the same in existing situations where list() is not given an array. References would behave as usual also. Test script: --------------- <?php function foo($a, list($b, &$c), $d) { echo "$a $c $b $d"; $c = 'Zero'; } $coconuts = array('One', 'Two', 'Three', 'Four'); foo(17, $coconuts, "radish"); echo "\n", $coconuts[1]; ?> Expected result: ---------------- 17 Two One radish Zero Actual result: -------------- At present it's a parse error, of course. -- Edit bug report at http://bugs.php.net/bug.php?id=51876&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51876&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51876&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51876&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51876&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51876&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51876&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51876&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51876&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51876&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51876&r=support Expected behavior: http://bugs.php.net/fix.php?id=51876&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51876&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51876&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51876&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51876&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51876&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51876&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51876&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51876&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51876&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51876&r=mysqlcfg