Search code examples
phplaravellaravel-10laravel-11

Unexpected token "readonly", expecting "abstract" or "final" or "class" PHP Error


I'm running Laravel Herd on a Mac with PHP v8.4.

And after I run composer update to upgrade from v10 to v11 I see this message in my application.

unexpected token "readonly", expecting "abstract" or "final" or "class" in sebastian/version/src/Version.php on line 23

Could I have PHP libraries that need an additional update?


Solution

  • You're running the wrong version of PHP. You've got packages installed that are for 8.4, but you're running it through PHP 8.1 or lower, as readonly was introduced in 8.2.

    You can see the class you're hitting the error on: https://github.com/sebastianbergmann/version/blob/main/src/Version.php#L26

    And here's information about readonly classes: https://stitcher.io/blog/readonly-classes-in-php-82