syntax error, unexpected identifier “readonly”, expecting “function” or “const”
Description
This syntax error signals that readonly is still considered as an identifier, and not as a keyword. This happens when the underlying PHP version is too old for the source code.
Example
<?php
class X {
readonly int $property;
}
?>
Alternatives
- Remove the
readonlyoption. - Upgrade to PHP 8.1 or more recent.
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See