Skip to content

Magento 2.4 syntax error, unexpected token “readonly”, expecting identifier#0

We are using Magento 2.4.5-p1 and php 8.1 version, upgrade command is working fine but when we try to run the di-compile command getting an error of

Repositories code generation... 1/9 [===>------------------------]  11% < 1 sec 139.0 MiBsyntax error, unexpected token "readonly", expecting identifier#0 /var/www/html/project_name/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php(117): MagentoSetupModuleDiCodeReaderClassesScanner->includeClass()
#1 /var/www/html/project_name/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php(87): MagentoSetupModuleDiCodeReaderClassesScanner->extract()
#2 /var/www/html/project_name/setup/src/Magento/Setup/Module/Di/App/Task/Operation/RepositoryGenerator.php(61): MagentoSetupModuleDiCodeReaderClassesScanner->getList()
#3 /var/www/html/project_name/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php(56): MagentoSetupModuleDiAppTaskOperationRepositoryGenerator->doOperation()
#4 /var/www/html/project_name/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php(216): MagentoSetupModuleDiAppTaskManager->process()
#5 /var/www/html/project_name/vendor/symfony/console/Command/Command.php(255): MagentoSetupConsoleCommandDiCompileCommand->execute()
#6 /var/www/html/project_name/vendor/symfony/console/Application.php(1021): SymfonyComponentConsoleCommandCommand->run()
#7 /var/www/html/project_name/vendor/symfony/console/Application.php(275): SymfonyComponentConsoleApplication->doRunCommand()
#8 /var/www/html/project_name/vendor/magento/framework/Console/Cli.php(116): SymfonyComponentConsoleApplication->doRun()
#9 /var/www/html/project_name/vendor/symfony/console/Application.php(149): MagentoFrameworkConsoleCli->doRun()
#10 /var/www/html/project_name/bin/magento(23): SymfonyComponentConsoleApplication->run()
#11 {main}

Also, this issue is also in GitHub but the not fully proper response – https://github.com/magento/magento2/issues/36521

Does anyone know how to resolve this?