syntax error, unexpected token “?->”

Description

This error reports that the object syntax was not expected there.

One classic reason is the new syntax in PHP 8.4, where parenthesis are not necessary, right after a new, to call properties or methods. This syntax actually requires the parenthesis.

Example

<?php

// should be new X()?->method();
new X?->method();

?>

Solutions

  • Add the parenthesis on the new call.