[Question] How to add a class constant inside an array ?
smknstd opened this issue · comments
Arnaud Becher commented
Hello, I'd like to add an item inside an associative array with a class "special constant":
[
'users' => \App\Models\User::class,
];
How I would do that with an ArrayItem:
use PhpParser\Node\Expr\ArrayItem;
...
new ArrayItem(
?, // how to print '\App\Models\User::class' ?
new String_('users')
),
Thanx
Nikita Popov commented
The ::class
constant is treated like a normal class constant. So you would create a new ClassConstFetch(new Name\FullyQualified('App\Models\User'), 'class')
or something along those lines.
Arnaud Becher commented
Thanx a lot