Details
-
New Feature
-
Status: Closed
-
Normal
-
Resolution: Done
-
None
-
None
-
1
-
Language 2015-04-29
-
New Feature
Description
when using the future parser, it allows for comma separated statements, and assignment to occur in these.
However, I would like to "splat" an array, using a similar syntax which currently is not supported
$input = 'example.org:www:filters:gzip text/html'
|
$title, $vhost, $valve, $filter = split_titles($input)
|
|
notice("\ntitle: ${title}\nvhost: ${vhost}\nvalve: ${valve}\nfilter: ${filter}")
|
This produced (with --parser=future) the following output:
title: main
|
vhost:
|
valve:
|
filter: [example.org, www, filters, gzip text_html]
|
We would like to have a syntax, such as
$input = 'example.org:www:filters:gzip text/html'
|
[ $title, $vhost, $valve, $filter ] = split_titles($input)
|
|
notice("\ntitle: ${title}\nvhost: ${vhost}\nvalve: ${valve}\nfilter: ${filter}")
|
Which produces the following output:
title: example.org
|
vhost: www
|
valve: filters
|
filter: gzip text_html
|
FOR DOCS
—
Multiple variables can be assigned in turn from an array. The variables on the LHS must be in an Array and there must be an equal number of
values in the assigned value array. If the value is not an Array it is treated as an Array of one element. Multi variable assignment supports sub-arrays
of variables to match sub-arrays of values.
# examples
|
[$a, $b, $c] = [1,2,3] # $a = 1, $b = 2, $c = 3
|
[$a, [$b, $c]] = [1,[2,3]] # $a = 1, $b = 2, $c = 3
|
[$a, $b] = [1, [2]] # $a = 1, $b = [2]
|
[$a, [$b]] = [1, [2]] # $a = 1, $b = 2
|
QA
—
risk: medium
probability: medium
severity: medium/low (work arounds available)
test layer: unit