syntax error, unexpected token “{”, expecting “,” or “;”¶
Description¶
PHP 8.4 introduced property hooks, which allow defining getters and setters for properties directly in the property definition. Previous PHP versions did not support that syntax, and yield this error.
Example¶
<?php
class A {
public $prop {
get { return A; }
set { echo __METHOD__, \n; }
}
}
?>
Solutions¶
Upgrade to PHP 8.4.
Remove the property hooks.
Move the property hooks to a method.
Move the property hooks to a magic method.
In previous PHP versions, this error message used to be Array and string offset access syntax with curly braces is deprecated.