How can I use a class constant as key in a Twig array/object/hashmap? When I try this
{ constant('App\\Entity\\User::FOO'): 'bar' }
... I'm getting this error:
A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "(" ("punctuation" expected with value ":").
However, it does work the other way aroung (ie using the constant as value):
{ 'bar': constant('App\\Entity\\User::FOO') }
只需将constant()
括在括号中,如下所示:
{ (constant('App\\Entity\\User::FOO')): 'bar' }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.