syntax error, unexpected token “new”, expecting “)”

Description

This error is a variation of the named parameter typo: the missing semi colon between the name and the value leads to an identifier next to an unrelated operator. The suggestion to use a closing parenthese is valid, though not the only one.

Example

<?php

foo(arg new B());

class B {}

function foo(B $arg) {}

?>

Solutions

  • Add the missing : before the new operator.

  • Add the missing ) before the new operator, and add a semi-colon or a comman, depending on the context.