syntax error, unexpected token “(”, expecting identifier or variable or “{” or “$”¶
Description¶
The object operators -> and ?-> both expect a name as second operand, aka on the right. Here, the name of the method was forgotten and the operator tried to use ( as a name, which is not allowed.
Example¶
<?php
// missing a method name
$object-> ();
// missing a method name
$object?-> (1);
?>
Solutions¶
Add a name after the
->and?->, such as$object->method.Add a name inside a variable after the
->and?->, such as$object->$methodName.Add a name inside an expression after the
->and?->, such as$object->{$variable . 'suffix'}().Add a name inside an variable variable after the
->and?->, such as$object->$$variable().