php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51876 Assigning to list(); list() as an lvalue
Submitted: 2010-05-21 00:54 UTC Modified: 2011-01-01 00:01 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: a at b dot c dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: a at b dot c dot de
New email:
PHP Version: OS:

 

 [2010-05-21 00:54 UTC] a at b dot c dot de
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-01 00:01 UTC] jani@php.net
-Status: Open +Status: Bogus
 [2011-01-01 00:01 UTC] jani@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 22:01:28 2024 UTC