php 8 expected expression operand but got T_NAME_FULLY_QUALIFIED
When using dmu_upgrade and PHP 8, I get the error
Indexing...
done.
[warning] my_module does not implement hook_block_configure.
[error] Error at line 26:14 in file /var/www/html/web/modules/custom/my_module/my_module.module: excepted expression operand but got T_NAME_FULLY_QUALIFIED
[notice] #0 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(1227): Pharborist\Parser->exprOperand()
#1 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(525): Pharborist\Parser->expr()
#2 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(484): Pharborist\Parser->exprStatement()
#3 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(2291): Pharborist\Parser->statement()
#4 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(2239): Pharborist\Parser->innerStatement()
#5 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(2250): Pharborist\Parser->innerStatementList(Object(Pharborist\StatementBlockNode), '}')
#6 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(461): Pharborist\Parser->innerStatementBlock()
#7 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(575): Pharborist\Parser->statement()
#8 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(424): Pharborist\Parser->_if()
#9 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(2291): Pharborist\Parser->statement()
#10 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(2239): Pharborist\Parser->innerStatement()
#11 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(2250): Pharborist\Parser->innerStatementList(Object(Pharborist\StatementBlockNode), '}')
#12 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(2228): Pharborist\Parser->innerStatementBlock()
#13 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(2166): Pharborist\Parser->body(Object(Pharborist\Functions\FunctionDeclarationNode))
#14 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(356): Pharborist\Parser->functionDeclaration()
#15 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(321): Pharborist\Parser->topStatement()
#16 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(202): Pharborist\Parser->topStatementList(Object(Pharborist\RootNode))
#17 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(240): Pharborist\Parser->buildTree(Object(Pharborist\TokenIterator))
#18 /var/www/html/vendor/jcnventura/pharborist/src/Parser.php(219): Pharborist\Parser::parseSource('<?php\n\n/**\n * @...', '/var/www/html/w...')
#19 /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Target.php(211): Pharborist\Parser::parseFile('/var/www/html/w...')
#20 /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Indexer/Functions.php(111): Drupal\drupalmoduleupgrader\Target->open('/var/www/html/w...')
#21 /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/ConverterBase.php(67): Drupal\drupalmoduleupgrader\Plugin\DMU\Indexer\Functions->get('my_module_block...')
#22 /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Blocks.php(40): Drupal\drupalmoduleupgrader\ConverterBase->executeHook(Object(Drupal\drupalmoduleupgrader\Target), 'hook_block_info')
#23 /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Commands/DrupalmoduleupgraderCommands.php(188): Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Blocks->convert(Object(Drupal\drupalmoduleupgrader\Target))
#24 [internal function]: Drupal\drupalmoduleupgrader\Commands\DrupalmoduleupgraderCommands->upgrade('my_module', Array)
#25 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#26 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#27 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#28 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(350): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#29 /var/www/html/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#30 /var/www/html/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#31 /var/www/html/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#32 /var/www/html/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /var/www/html/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#36 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
#37 /var/www/html/vendor/bin/drush(117): include('/var/www/html/v...')
#38 {main}
The error is thrown because it converts some of the file to Drupal 9 syntax, then it runs again maybe, and fails on line 26 which has become $cache = \Drupal::cache('cache_block')->get($cid);?
line 26:14 is the backslash.
Steps to reproduce
Try to upgrade the attached module when using PHP 8.0
Comments
Comment #2
solideogloria commentedThe module is basically unusable with PHP 8 right now.
Comment #3
joseph.olstadmight be related:
#3287082: Make dmu-upgrade itself run without errors on Drupal 10
I'll push the rector fixes for D10 compatibility, might help.
Comment #4
joseph.olstadComment #5
joseph.olstadComment #6
joseph.olstadComment #7
gábor hojtsyI posted #3301592: Drupal module upgrader tests fail on PHP 7.3 which passes fine :) Once that lands, we can start looking at PHP 7.4 in #3301606: Drupal module upgrader tests fail on PHP 7.3 and PHP 7.4 :)
Comment #8
joseph.olstadok I tagged 8.x-1.9 which is now thanks to Gàbor Hojtsy compatible with PHP 7.4
TODO: fixes for PHP 8.0 and 8.1 compatibility.
Comment #9
gábor hojtsyLet's retitle for that. Also no patch yet so marking as active.
Comment #10
gábor hojtsyComment #12
gábor hojtsySo I set up a drupalpod with this
mymodulesample provided (thanks!). Although the tests fail a similar way. Strange thing is the dmu-analyse and dmu-upgrade does not fail that bad on this PHP 8.1, so maybe it is not actually running PHP 8.1 (the phpinfo on Drupal also says its PHP 8.1, hm):Comment #13
gábor hojtsySame drupalpod, I don't have much luck running the phpunit tests, which may be an autoloader problem?!
Comment #14
liam morlandComment #15
gábor hojtsyComment #16
gábor hojtsySo what people are finding is analyzing on PHP 8.0/8.1 runs fine, but not making the automated fixes. So one interim fix we can introduce to make it compatible with Drupal 10 is that we bail in the automated fix drush command when on PHP 8.0+, and point to this issue :) But say people can still run the analyze thing. That would be one step more useful compared to not being compatible at all.
I worked on https://github.com/jcnventura/pharborist/pull/1 and @jcnventura landed it but it did not yet quite resolve all PHP 8 problems.
I think #3287082: Make dmu-upgrade itself run without errors on Drupal 10 would be the best place to do that workaround for now.
Comment #17
solideogloria commentedComment #18
solideogloria commentedComment #20
andyf commentedI've set up GitLab CI. I was hoping to have a matrix where we could test D9 with PHP 8.1, but that didn't work, so we're now just testing:
D9/PHP 7.4 is already failing without changes from this branch, see #3465500: Use GitLab CI and fix tests. I'm not sure how best to continue testing D9 when the template variables are adjusted and the current stable becomes 11.
Comment #21
andyf commentedJust FYI I've forked pharborist and started working on updating it so the tests pass on higher versions of PHP. I've got it passing on 8.0, and using that the tests for this module also pass on 8.0 except for the existing failure mentioned in #20.
I'm going to look at getting it working with 8.1 now.
Comment #22
andyf commentedTests of pharborist and drupalmoduleupgrader pass with 8.1 using the latest from the fork.
Comment #23
jcnventuraComment #24
jcnventuraPlease do a pull request on upstream pharborist.
Comment #25
andyf commentedThanks @jcnventura! I've made a PR - I had been hanging on, I haven't actually tested the changes by upgrading a module, I've only ensured the tests pass. I was thinking it might make sense to create a script that would use ddev to fire up a D9 site, install some modules and upgrade them, then do the same again with a D10 site, and compare the output... but I haven't found time yet.
Comment #26
andyf commentedI've also opened a ticket to get tests running on
pharborist/pharborist, not sure if that issue queue will be checked or who might have the access to set something up.Comment #27
jcnventuraOnce you accept the invite, I guess you'll have the access for that :)
Comment #28
andyf commentedNeato, thanks (: I assume we're ok using GitHub actions, which will use up minutes from the pharborist org IIUC.
Comment #29
jcnventuraYes, we don't use those for anything else, and I assume the free tier will be enough...
Comment #30
gábor hojtsyI merged the work from @andyF to Pharborist and then let Claude Code fix the remaining PHP 8 compatibility issues (there was not much). It even added further regression testing for the new tokenization constants. After more fixes to the tests https://www.drupal.org/project/drupalmoduleupgrader/releases/2.0.0-alpha2 is now out! Made in less than a day with Claude Code. I'll credit folks here that contributed a lot to this effort.
Comment #32
gábor hojtsy