Skip to content

Add syntax for destructuring assignment #3399

@hason

Description

@hason

Add destructuring assignment syntax that makes it possible to unpack values from arrays, or properties from objects, into distinct variables (as same is in Javascript):

A twig template

{% set [a, b] = [1, 2] %} 
{% for {id, firstName, ...rest} in data %}
{% endfor %}

should be converted to

[$a, $b] = [1, 2];
foreach ($data as ['id' => $id, 'firstName' => $firstName]) {
    // TODO support for ...rest
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions