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 was forgotten and the operator tried to use =
as a name, which is not allowed.
Example¶
<?php
// missing a property
$object-> = 3;
// missing a property
$object?-> = 3;
?>
Solutions¶
Add a name after the
->
and?->
, such as$object->property
.Add a name inside a variable after the
->
and?->
, such as$object->$name
.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
.