Skip to content

[Idea] make render variables 'key' => 'value' not mandatory #4509

Answered by stof
Nayte91 asked this question in Q&A
Discussion options

You must be logged in to vote

This is a feature request you would have to send to PHP, not to Twig, as you are asking about a different way to write a PHP associative array.
There is no way to emulate that when receiving an array that does not have string keys, as there is no way to know the name of the variable that was used when building the array (it has to be something done when parsing the code).

But this would be rejected anyway, because [$sameAsVariable, 'not_same' => $foo] is already valid PHP code that has a different behavior, and so it would be impossible to make sure RFC pass in PHP (Twig and JS were able to introduce this shortcut syntax because they have different delimiters { } vs [ ] making it unambigu…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Nayte91
Comment options

@GromNaN
Comment options

@stof
Comment options

stof Dec 18, 2024
Collaborator

Answer selected by Nayte91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants