Previous version
Magento 2.4.5 and php 7.4
After upgrade php version 8.1 getting compile error
< 1 sec 117.0 MiBsyntax error, unexpected token “<“#0 /var/www/html/magento/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php(117): MagentoSetupModuleDiCodeReaderClassesScanner->includeClass()
#1 /var/www/html/magento/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php(87): MagentoSetupModuleDiCodeReaderClassesScanner->extract()
#2 /var/www/html/magento/setup/src/Magento/Setup/Module/Di/App/Task/Operation/RepositoryGenerator.php(61): MagentoSetupModuleDiCodeReaderClassesScanner->getList()
#3 /var/www/html/magento/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php(56): MagentoSetupModuleDiAppTaskOperationRepositoryGenerator->doOperation()
#4 /var/www/html/magento/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php(216): MagentoSetupModuleDiAppTaskManager->process()
After debug the code in /var/www/html/magento/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php file its getting error related with private function.
private function includeClass(string $className, string $fileItemPath): bool
{
if (!class_exists($className)) {
// phpcs:ignore
require_once $fileItemPath;
return true;
}
return false;
}
So I remove the function and write the code directly called function. But I have seen same error is getting at compile time which define at private function.
private function extract(RecursiveIteratorIterator $recursiveIterator)
After that didnt get any solution then downgrade the PHP version 8.1 to 7.4. But this time again getting following error.
PHP Fatal error: Uncaught Error: Call to undefined function SymfonyComponentConsolemb_detect_encoding() in /usr/share/php/Symfony/Component/Console/Application.php:1146
Stack trace:
#0 /usr/share/php/Symfony/Component/Console/Application.php(806): SymfonyComponentConsoleApplication->splitStringByWidth()
#1 /usr/share/php/Symfony/Component/Console/Application.php(776): SymfonyComponentConsoleApplication->doRenderException()
#2 /usr/share/php/Symfony/Component/Console/Application.php(132): SymfonyComponentConsoleApplication->renderException()
#3 /usr/share/php/Symfony/Component/Console/Application.php(155): SymfonyComponentConsoleApplication->SymfonyComponentConsole{closure}()
#4 /usr/share/php/Composer/Console/Application.php(113): SymfonyComponentConsoleApplication->run()
#5 /usr/bin/composer(62): ComposerConsoleApplication->run()
#6 {main}
thrown in /usr/share/php/Symfony/Component/Console/Application.php on line 1146