nikic / PHP-Parser

A PHP parser written in PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] How to add a class constant inside an array ?

smknstd opened this issue · comments

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

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.

Thanx a lot