rfc:destructuring_coalesce
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:destructuring_coalesce [2022/10/16 21:07] – bwoebi | rfc:destructuring_coalesce [2022/11/26 15:07] (current) – updated status. danack | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2022-10-14 | * Date: 2022-10-14 | ||
* Author: Bob Weinand < | * Author: Bob Weinand < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 12: | Line 12: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes the usage of the ''??'' | + | This RFC proposes the usage of the ''??'' |
In its simplest form the destructuring coalesce will be written as follows: | In its simplest form the destructuring coalesce will be written as follows: | ||
Line 27: | Line 27: | ||
[[$a, $b] ?? [1, 2]] = $array; // if $array[0] is null or does not exist, $a will be 1 and $b will be 2 | [[$a, $b] ?? [1, 2]] = $array; // if $array[0] is null or does not exist, $a will be 1 and $b will be 2 | ||
</ | </ | ||
+ | |||
+ | Also note that, equivalently to how ''??'' | ||
==== Use cases ==== | ==== Use cases ==== | ||
+ | |||
Exploding an externally provided string, e.g. a key-value pair separated by '' | Exploding an externally provided string, e.g. a key-value pair separated by '' | ||
<PHP> | <PHP> | ||
Line 49: | Line 52: | ||
) = json_decode($json) ?: []; | ) = json_decode($json) ?: []; | ||
// $name = "Bob Weinand", | // $name = "Bob Weinand", | ||
+ | </ | ||
+ | |||
+ | Filling in '' | ||
+ | <PHP> | ||
+ | $data = [1, 2, null]; | ||
+ | list($a, $b, $c ?? 3) = $data; | ||
+ | // $a = 1, $b = 2, $c = 3 | ||
</ | </ | ||
Line 130: | Line 140: | ||
</ | </ | ||
checking for the existence of '' | checking for the existence of '' | ||
+ | |||
+ | ==== Discussion of syntax ==== | ||
+ | |||
+ | This RFC proposes using ''??'' | ||
+ | |||
+ | Other languages like Javascript have constructs like '' | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 139: | Line 155: | ||
There' | There' | ||
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
- | Add a destructuring coalesce feature as described? | + | A 2/3 majority is required. The vote started 2022-11-07 and ended 2022-11-21. |
- | A 2/3 majority is required. | + | <doodle title=" |
+ | * Yes | ||
+ | * No | ||
+ | </doodle> | ||
===== Implementation ===== | ===== Implementation ===== |
rfc/destructuring_coalesce.1665954479.txt.gz · Last modified: 2022/10/16 21:07 by bwoebi