plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

Parse Error: unexpected T_CLASS for `new class {}::class;`

Open wowu opened this issue 2 months ago • 1 comments

@prettier/plugin-php v0.24.0 Playground link

Input:

<?php

new class {}::class;

Output:

Parse Error : syntax error, unexpected 'class' (T_CLASS) on line 3

  1 | <?php
  2 |
> 3 | new class {}::class;
    |              ^

Workaround I recommend to use for now:

get_class(new class {});

wowu avatar Oct 23 '25 10:10 wowu

https://github.com/glayzzle/php-parser/issues/1135

jorgsowa avatar Nov 05 '25 15:11 jorgsowa