php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70094 Allow default values for list()
Submitted: 2015-07-18 01:44 UTC Modified: 2015-07-18 10:00 UTC
Votes:4
Avg. Score:2.8 ± 1.8
Reproduced:2 of 4 (50.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: andreas at dqxtech dot net Assigned:
Status: Open Package: Arrays related
PHP Version: 5.6.11 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
37 - 28 = ?
Subscribe to this entry?

 
 [2015-07-18 01:44 UTC] andreas at dqxtech dot net
Description:
------------
Sometimes I want to use the list() construct to unpack an array, but I don't know the size of the array. In this case, list() will give me a "Notice: Undefined index ..".

It would be nice if I could specify default values, as in the code below.

Test script:
---------------
<?php

list($a, $b = 'bbb', $c = 'ccc') = array('AAA', 'BBB');
print "$a, $b, $c";

// Output: "AAA, BBB, ccc".


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-18 10:00 UTC] cmb@php.net
-Package: PHP Language Specification +Package: Arrays related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC