3535 * path: string,
3636 * expression: bool,
3737 * literal: bool,
38+ * new_without_parens: bool,
3839 * }
3940 */
4041class CallFinder
@@ -194,7 +195,7 @@ public static function getFunctionCalls(string $source, int $line, $function): a
194195 }
195196
196197 if (!KINT_PHP84 ) {
197- self ::$ operator [T_NEW ] = true ;
198+ self ::$ operator [T_NEW ] = true ; // @codeCoverageIgnore
198199 }
199200
200201 /** @psalm-var list<PhpToken> */
@@ -397,6 +398,7 @@ public static function getFunctionCalls(string $source, int $line, $function): a
397398 $ path = self ::tokensToString (self ::tokensTrim ($ param ['full ' ]));
398399 $ expression = false ;
399400 $ literal = false ;
401+ $ new_without_parens = false ;
400402
401403 foreach ($ name as $ token ) {
402404 if (self ::tokenIsOperator ($ token )) {
@@ -405,6 +407,38 @@ public static function getFunctionCalls(string $source, int $line, $function): a
405407 }
406408 }
407409
410+ // As of 8.4 new is only an expression when parentheses are
411+ // omitted. In that case we can cheat and add them ourselves.
412+ //
413+ // > PHP interprets the first expression after new as a class name
414+ // per https://wiki.php.net/rfc/new_without_parentheses
415+ if (KINT_PHP84 && !$ expression && T_NEW === $ name [0 ][0 ]) {
416+ $ had_name_token = false ;
417+ $ new_without_parens = true ;
418+
419+ foreach ($ name as $ token ) {
420+ if (T_NEW === $ token [0 ]) {
421+ continue ;
422+ }
423+
424+ if (isset (self ::$ ignore [$ token [0 ]])) {
425+ continue ;
426+ }
427+
428+ if (T_CLASS === $ token [0 ]) {
429+ $ new_without_parens = false ;
430+ break ;
431+ }
432+
433+ if ('( ' === $ token && $ had_name_token ) {
434+ $ new_without_parens = false ;
435+ break ;
436+ }
437+
438+ $ had_name_token = true ;
439+ }
440+ }
441+
408442 if (!$ expression && 1 === \count ($ name )) {
409443 switch ($ name [0 ][0 ]) {
410444 case T_CONSTANT_ENCAPSED_STRING :
@@ -440,6 +474,7 @@ public static function getFunctionCalls(string $source, int $line, $function): a
440474 'path ' => $ path ,
441475 'expression ' => $ expression ,
442476 'literal ' => $ literal ,
477+ 'new_without_parens ' => $ new_without_parens ,
443478 ];
444479 }
445480
@@ -605,7 +640,7 @@ private static function tokensFormatted(array $tokens): array
605640 continue ;
606641 }
607642
608- $ token = ' ' ;
643+ $ token[ 1 ] = ' ' ;
609644 $ space = true ;
610645 } else {
611646 if (KINT_PHP80 && null !== $ last && T_ATTRIBUTE === $ last [0 ]) {
0 commit comments