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:3
Avg. Score:3.3 ± 1.7
Reproduced:2 of 3 (66.7%)
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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-2019 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 11:01:27 2019 UTC