TYPO3 / Surf

Easy and powerful PHP deployment tool
https://docs.typo3.org/other/typo3/surf/master/en-us/
GNU General Public License v3.0
98 stars 53 forks source link

PHP class-attribute types resulting in error [ ParseError ] syntax error, unexpected 'MyModel' (T_STRING) #437

Closed Moongazer closed 2 years ago

Moongazer commented 3 years ago

If we set class-attribute types in models or other classes (strict_types = 1), the deployment breaks with very strange errors:

[2020-12-13 11:23:43] TYPO3 Surf.INFO: MyProject (TYPO3 CMS) TYPO3\Surf\Task\TYPO3\CMS\CompareDatabaseTask [] []
[2020-12-13 11:23:43] TYPO3 Surf.DEBUG: $MyProject: "test -f '/www/htdocs/w6297434/releases/20201213112320/vendor/bin/typo3cms'" [] []
[2020-12-13 11:23:43] TYPO3 Surf.DEBUG: $MyProject: "test -f '/www/htdocs/w6297434/releases/20201213112320/vendor/bin/typo3cms'" [] []
[2020-12-13 11:23:43] TYPO3 Surf.DEBUG: $MyProject: "cd '/www/htdocs/w6297434/releases/20201213112320' && TYPO3_CONTEXT='Development' php 'vendor/bin/typo3cms' 'database:updateschema' '*.add,*.change'" [] []
[2020-12-13 11:23:44] TYPO3 Surf.ERROR:     >  [] []
[2020-12-13 11:23:44] TYPO3 Surf.ERROR:     > [ ParseError ] syntax error, unexpected 'MyModel' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) Exception trace: #0 ()    packages/my_extension/Classes/Domain/Model/MyModel.php:19 #1 Composer\Autoload\includeFile()    vendor/composer/ClassLoader.php:322 #2 Composer\Autoload\ClassLoader->loadClass()    vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:135 #3 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClass()    vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:123 [] []
[2020-12-13 11:23:44] TYPO3 Surf.DEBUG:     >  [] []
[2020-12-13 11:23:44] TYPO3 Surf.ERROR:     > #4 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClassWithAlias() #5 spl_autoload_call() #6 class_exists()    vendor/symfony/config/Resource/ClassExistenceResource.php:84 #7 Symfony\Component\Config\Resource\ClassExistenceResource->isFresh()    vendor/symfony/dependency-injection/ContainerBuilder.php:348 #8 Symfony\Component\DependencyInjection\ContainerBuilder->getReflectionClass()    vendor/symfony/dependency-injection/Loader/FileLoader.php:199 #9 Symfony\Component\DependencyInjection\Loader\FileLoader->findClasses()    vendor/symfony/dependency-injection/Loader/FileLoader.php:99 #10 Symfony\Component\DependencyInjection\Loader\FileLoader->registerClasses()    vendor/symfony/dependency-injection/Loader/YamlFileLoader.php:671 #11 Symfony\Component\DependencyInjection\Loader\YamlFileLoader->parseDefinition()    vendor/symfony/dependency-injection/Loader/YamlFileLoader.php:234 #12 Symfony\Component\DependencyInjection\Loader\YamlFileLoader->parseDefinitions()    vendor/symfony/dependency-injection/Loader/YamlFileLoader.php:154 #13 Symfony\Component\DependencyInjection\Loader\YamlFileLoader->load()    typo3/sysext/core/Classes/DependencyInjection/ContainerBuilder.php:119 #14 TYPO3\CMS\Core\DependencyInjection\ContainerBuilder->buildContainer()    typo3/sysext/core/Classes/DependencyInjection/ContainerBuilder.php:84 #15 TYPO3\CMS\Core\DependencyInjection\ContainerBuilder->createDependencyInjectionContainer()    typo3/sysext/install/Classes/Service/LateBootService.php:79 #16 TYPO3\CMS\Install\Service\LateBootService->prepareContainer()    typo3/sysext/install/Classes/Service/LateBootService.php:65 #17 TYPO3\CMS\Install\Service\LateBootService->getContainer()    vendor/helhum/typo3-console/Classes/Console/Core/Kernel.php:135 #18 Helhum\Typo3Console\Core\Kernel->initialize()    vendor/helhum/typo3-console/Classes/Console/Core/Kernel.php:89 #19 Helhum\Typo3Console\Core\Kernel->handle()    vendor/helhum/typo3-console/Scripts/typo3-console.php:31 #20 {closure}()    vendor/helhum/typo3-console/Scripts/typo3-console.php:33 #21 require()    vendor/helhum/typo3-console/typo3cms:3 [] []
class MyModel extends AbstractEntity {
    protected ?string $name = NULL;
    protected AnotherType $anotherType;
}

If we remove the types, everything runs like before (before means, the same deployment run well before we used types for attributes). This happens not only to model but also for enable-column classes. We know that Extbase has some trouble with types set, but the application runs like expected during tests. Only the Surf deployment breaks.

TYPO3 v10.4.9 PHP v7.4 Surf v2.3.0

simonschaufi commented 3 years ago

Did you require surf directly in the typo3 project? This is not recommended. Either use a standalone project or use the surf.phar to avoid any side effects. See https://docs.typo3.org/other/typo3/surf/2.0/en-us/Installation/Index.html

Moongazer commented 3 years ago

No, not as dependency. I installed Surf like suggested in the manual in /usr/local/bin/surfand only having a .surf/MyDeployConfig.php file in the project repository.

t3easy commented 3 years ago

As Surf only interacts with TYPO3 by typo3_console, I think it could be a problem on @helhum package.

t3easy commented 3 years ago

I guess you get the same error if you run

TYPO3_CONTEXT='Development' php 'vendor/bin/typo3cms' 'database:updateschema' '*.add,*.change'

manually. As typo3_console also use core functionality it could be a core bug or "expected" behavior atm. because of the mentioned problems of extbase.

Moongazer commented 3 years ago

Unfortunately I can't check anymore as I switched to PHP Deployer :smiley_cat: But yes, the error might come from the same source where Extbase has its problems with, not sure what happens under the hood here.

t3easy commented 3 years ago

Do you run the same tasks with deployer?

Moongazer commented 3 years ago

No because I didn't know they are compatible, so I've rewritten the deployment script (based on sourcebroker/deployer-extended-typo3)

t3easy commented 3 years ago

They are not compatible, but you need a set of tasks, that every deployment tool have to run. To dig some deeper, please try to run the same shell command in your dev environment.

TYPO3_CONTEXT='Development' php 'vendor/bin/typo3cms' 'database:updateschema' '*.add,*.change'

(BTW.: Is Development the right context for the deployed site? Many use something like Production/Staging) Check the context and set it to the same, the webserver / fpm uses. Maybe the context is wrong and you have some settings that are changed for development.

Maybe it's a problem, that the php binary is a different version on your hosting cli than on the webserver. That's a common problem on some hosting environments.

fgerards commented 3 years ago

TYPO3 10.4.16, Surf 2.3.0 php 7.3.28 here --- got structurally the same type of error from helhum typo3-console when deploying with TYPO3 Surf: ` > [ ParseError ] syntax error, unexpected '|', expecting variable (T_VARIABLE) Exception trace: #0 () vendor/psr/cache/src/CacheItemInterface.php:104 #1 Composer\Autoload\includeFile() vendor/composer/ClassLoader.php:346 #2 Composer\Autoload\ClassLoader->loadClass() vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:135 #3 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClass() vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:123 #4 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClassWithAlias() #5 spl_autoload_call() vendor/symfony/cache-contracts/ItemInterface.php:23 #6 include() vendor/composer/ClassLoader.php:478 #7 Composer\Autoload\includeFile() vendor/composer/ClassLoader.php:346 #8 Composer\Autoload\ClassLoader->loadClass() vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:135 #9 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClass() vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:123

10 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClassWithAlias() #11 spl_autoload_call() vendor/symfony/cache/CacheItem.php:22 #12 include() vendor/composer/ClassLoader.php:478 #13 Composer\Autoload\includeFile() vendor/composer/ClassLoader.php:346 #14 Composer\Autoload\ClassLoader->loadClass() vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:135 #15 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClass() vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:123 #16 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClassWithAlias() #17 spl_autoload_call() #18 class_exists() vendor/symfony/cache/Adapter/AdapterInterface.php:18 #19 include() vendor/composer/ClassLoader.php:478 #20 Composer\Autoload\includeFile() vendor/composer/ClassLoader.php:346 #21 Composer\Autoload\ClassLoader->loadClass() vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:135 #22 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClass() vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:123 #23 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClassWithAlias() #24 spl_autoload_call() vendor/symfony/cache/Adapter/ArrayAdapter.php:29 #25 include() vendor/composer/ClassLoader.php:478 #26 Composer\Autoload\includeFile() vendor/composer/ClassLoader.php:346 #27 Composer\Autoload\ClassLoader->loadClass() vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:135 #28 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClass() vendor/typo3/class-alias-loader/src/ClassAliasLoader.php:123 #29 TYPO3\ClassAliasLoader\ClassAliasLoader->loadClassWithAlias() #30 spl_autoload_call() vendor/symfony/expression-language/ExpressionLanguage.php:39 #31 Symfony\Component\ExpressionLanguage\ExpressionLanguage->construct() typo3/sysext/core/Classes/ExpressionLanguage/Resolver.php:68 #32 TYPO3\CMS\Core\ExpressionLanguage\Resolver->construct() typo3/sysext/core/Classes/Utility/GeneralUtility.php:3441 #33 TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance() typo3/sysext/core/Classes/Site/Entity/Site.php:160 #34 TYPO3\CMS\Core\Site\Entity\Site->resolveBaseWithVariants() typo3/sysext/core/Classes/Site/Entity/Site.php:103 #35 TYPO3\CMS\Core\Site\Entity\Site->construct() typo3/sysext/core/Classes/Utility/GeneralUtility.php:3441 #36 TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance() typo3/sysext/core/Classes/Configuration/SiteConfiguration.php:137 #37 TYPO3\CMS\Core\Configuration\SiteConfiguration->resolveAllExistingSites() typo3/sysext/core/Classes/Configuration/SiteConfiguration.php:88 #38 TYPO3\CMS\Core\Configuration\SiteConfiguration->getAllExistingSites() typo3/sysext/core/Classes/Site/SiteFinder.php:143 #39 TYPO3\CMS\Core\Site\SiteFinder->fetchAllSites() typo3/sysext/core/Classes/Site/SiteFinder.php:57 #40 TYPO3\CMS\Core\Site\SiteFinder->construct() typo3/sysext/core/Classes/Utility/GeneralUtility.php:3441 #41 TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance() typo3/sysext/core/Classes/TypoScript/TemplateService.php:1236 #42 TYPO3\CMS\Core\TypoScript\TemplateService->addDefaultTypoScript() typo3/sysext/core/Classes/TypoScript/TemplateService.php:614 #43 TYPO3\CMS\Core\TypoScript\TemplateService->runThroughTemplates() typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php:74 #44 TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager->getTypoScriptSetup() typo3/sysext/extbase/Classes/Configuration/AbstractConfigurationManager.php:217 #45 TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager->getExtbaseConfiguration() typo3/sysext/extbase/Classes/Configuration/AbstractConfigurationManager.php:151 #46 TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager->getConfiguration() typo3/sysext/extbase/Classes/Configuration/ConfigurationManager.php:123 #47 TYPO3\CMS\Extbase\Configuration\ConfigurationManager->getConfiguration() typo3/sysext/extbase/Classes/Configuration/ConfigurationManager.php:143 #48 TYPO3\CMS\Extbase\Configuration\ConfigurationManager->isFeatureEnabled() typo3/sysext/extbase/Classes/Persistence/Generic/Typo3QuerySettings.php:112 #49 TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings->initializeObject() typo3/sysext/extbase/Classes/Object/Container/Container.php:252 #50 TYPO3\CMS\Extbase\Object\Container\Container->initializeObject() typo3/sysext/extbase/Classes/Object/Container/Container.php:169 #51 TYPO3\CMS\Extbase\Object\Container\Container->getInstanceInternal() typo3/sysext/extbase/Classes/Object/Container/Container.php:111 #52 TYPO3\CMS\Extbase\Object\Container\Container->getInstance() typo3/sysext/extbase/Classes/Object/ObjectManager.php:114 #53 TYPO3\CMS\Extbase\Object\ObjectManager->get() typo3/sysext/extensionmanager/Classes/Domain/Repository/ExtensionRepository.php:46 #54 TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository->initializeObject() var/cache/code/di/DependencyInjectionContainer_c4b4e7362895b4274d6316b7b1b2f5c106dbf171.php:8273 #55 DependencyInjectionContainer_c4b4e7362895b4274d6316b7b1b2f5c106dbf171->getExtensionRepositoryService() var/cache/code/di/DependencyInjectionContainer_c4b4e7362895b4274d6316b7b1b2f5c106dbf171.php:8321 #56 DependencyInjectionContainer_c4b4e7362895b4274d6316b7b1b2f5c106dbf171->getDependencyUtilityService() var/cache/code/di/DependencyInjectionContainer_c4b4e7362895b4274d6316b7b1b2f5c106dbf171.php:8384 #57 DependencyInjectionContainer_c4b4e7362895b4274d6316b7b1b2f5c106dbf171->getInstallUtilityService() vendor/symfony/dependency-injection/Container.php:248 #58 Symfony\Component\DependencyInjection\Container->make() vendor/symfony/dependency-injection/Container.php:228 #59 Symfony\Component\DependencyInjection\Container->get() typo3/sysext/extbase/Classes/Object/ObjectManager.php:105 #60 TYPO3\CMS\Extbase\Object\ObjectManager->get() vendor/helhum/typo3-console/Classes/Console/Extension/ExtensionSetup.php:50 #61 Helhum\Typo3Console\Extension\ExtensionSetup->construct() vendor/helhum/typo3-console/Classes/Console/Command/Extension/ExtensionStateCommandsHelper.php:61 #62 Helhum\Typo3Console\Command\Extension\ExtensionStateCommandsHelper->construct() vendor/helhum/typo3-console/Classes/Console/Command/Extension/ExtensionSetupActiveCommand.php:51 #63 Helhum\Typo3Console\Command\Extension\ExtensionSetupActiveCommand->execute() vendor/symfony/console/Command/Command.php:255 #64 Symfony\Component\Console\Command\Command->run() vendor/symfony/console/Application.php:1009 #65 Symfony\Component\Console\Application->doRunCommand() vendor/helhum/typo3-console/Classes/Console/Mvc/Cli/Symfony/Application.php:189 #66 Helhum\Typo3Console\Mvc\Cli\Symfony\Application->doRunCommand() vendor/symfony/console/Application.php:273 #67 Symfony\Component\Console\Application->doRun() vendor/symfony/console/Application.php:149 #68 Symfony\Component\Console\Application->run() vendor/helhum/typo3-console/Classes/Console/Core/Kernel.php:113 #69 Helhum\Typo3Console\Core\Kernel->handle() vendor/helhum/typo3-console/Scripts/typo3-console.php:31 #70 {closure}() vendor/helhum/typo3-console/Scripts/typo3-console.php:33 #71 require() vendor/helhum/typo3-console/typo3cms:3`

If I run TYPO3_CONTEXT='Development' php 'vendor/bin/typo3cms' 'extension:setupactive' on SSH console, everything works fine

sabbelasichon commented 2 years ago

Never had such an issue. Feel free to reopen

Kokil commented 2 years ago

Same here