Support PHP 8.1
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3542301. -->
Reported by: [lpeabody](https://www.drupal.org/user/1137356)
Related to !171
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>Drupal core 10.x supports PHP 8.1. So long as this module specifies it can be installed alongside a Drupal >=10.3 codebase, it should assume that it could be installed in a PHP 8.1 environment.</p>
<p>The latest 1.2.x only supports PHP 8.3 due to src/Plugin/ModelerApiModelOwner/Agent.php:</p>
<pre> ------ ---------------------------------------------------------------------------- <br> Line Agent.php <br> ------ ---------------------------------------------------------------------------- <br> 35 Class constants with native types are supported only on PHP 8.3 and later. <br> ------ ----------------------------------------------------------------------------</pre><h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>- Be running PHP 8.1.<br>
- Install ai_agents 1.2.x.<br>
- Get the following error:</p>
<pre>ParseError: syntax error, unexpected identifier "SUPPORTED_COMPONENT_TYPES", expecting "=" in /opt/drupal/web/modules/contrib/ai_agents/src/Plugin/ModelerApiModelOwner/Agent.php on line 35 #0 /opt/drupal/vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}('/opt/drupal/web...')<br>#1 [internal function]: Composer\Autoload\ClassLoader->loadClass('Drupal\\ai_agent...')<br>#2 /opt/drupal/web/core/lib/Drupal/Component/Plugin/Discovery/AttributeClassDiscovery.php(139): ReflectionClass->__construct('Drupal\\ai_agent...')<br>#3 /opt/drupal/web/core/lib/Drupal/Component/Plugin/Discovery/AttributeClassDiscovery.php(84): Drupal\Component\Plugin\Discovery\AttributeClassDiscovery->parseClass('Drupal\\ai_agent...', Object(SplFileInfo))<br>#4 /opt/drupal/web/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(86): Drupal\Component\Plugin\Discovery\AttributeClassDiscovery->getDefinitions()<br>#5 /opt/drupal/web/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php(337): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDefinitions()<br>#6 /opt/drupal/web/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php(213): Drupal\Core\Plugin\DefaultPluginManager->findDefinitions()<br>#7 /opt/drupal/web/modules/contrib/modeler_api/src/Plugin/ModelOwnerPluginManager.php(59): Drupal\Core\Plugin\DefaultPluginManager->getDefinitions()<br>#8 /opt/drupal/web/modules/contrib/modeler_api/src/Hook/EntityHooks.php(332): Drupal\modeler_api\Plugin\ModelOwnerPluginManager->getAllInstances(true)<br>#9 /opt/drupal/web/modules/contrib/modeler_api/modeler_api.module(56): Drupal\modeler_api\Hook\EntityHooks->systemInfoAlter(Array, Object(Drupal\Core\Extension\Extension), 'module')<br>#10 /opt/drupal/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(552): modeler_api_system_info_alter(Array, Object(Drupal\Core\Extension\Extension), 'module')<br>#11 /opt/drupal/web/core/lib/Drupal/Core/Extension/ExtensionList.php(321): Drupal\Core\Extension\ModuleHandler->alter('system_info', Array, Object(Drupal\Core\Extension\Extension), 'module')<br>#12 /opt/drupal/web/core/lib/Drupal/Core/Extension/ModuleExtensionList.php(155): Drupal\Core\Extension\ExtensionList->doList()<br>#13 /opt/drupal/web/core/lib/Drupal/Core/Extension/ExtensionList.php(283): Drupal\Core\Extension\ModuleExtensionList->doList()<br>#14 /opt/drupal/vendor/drush/drush/src/Commands/pm/PmCommands.php(324): Drupal\Core\Extension\ExtensionList->getList()<br>#15 /opt/drupal/vendor/drush/drush/src/Commands/pm/PmCommands.php(120): Drush\Commands\pm\PmCommands->addInstallDependencies(Array)<br>#16 /opt/drupal/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ValidateHookDispatcher.php(53): Drush\Commands\pm\PmCommands->validateEnableModules(Object(Consolidation\AnnotatedCommand\CommandData))<br>#17 /opt/drupal/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ValidateHookDispatcher.php(42): Consolidation\AnnotatedCommand\Hooks\Dispatchers\ValidateHookDispatcher->doValidator(Array, Object(Consolidation\AnnotatedCommand\CommandData))<br>#18 /opt/drupal/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ValidateHookDispatcher.php(29): Consolidation\AnnotatedCommand\Hooks\Dispatchers\ValidateHookDispatcher->callValidator(Array, Object(Consolidation\AnnotatedCommand\CommandData))<br>#19 /opt/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(195): Consolidation\AnnotatedCommand\Hooks\Dispatchers\ValidateHookDispatcher->validate(Object(Consolidation\AnnotatedCommand\CommandData))<br>#20 /opt/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))<br>#21 /opt/drupal/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))<br>#22 /opt/drupal/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))<br>#23 /opt/drupal/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))<br>#24 /opt/drupal/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))<br>#25 /opt/drupal/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))<br>#26 /opt/drupal/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))<br>#27 /opt/drupal/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))<br>#28 /opt/drupal/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)<br>#29 /opt/drupal/vendor/drush/drush/drush(4): require('/opt/drupal/ven...')<br>#30 /opt/drupal/vendor/bin/drush(119): include('/opt/drupal/ven...')<br>#31 {main}<br>ParseError: syntax error, unexpected identifier "SUPPORTED_COMPONENT_TYPES", expecting "=" in Composer\Autoload\{closure}() (line 35 of /opt/drupal/web/modules/contrib/ai_agents/src/Plugin/ModelerApiModelOwner/Agent.php).</pre><h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>- Scan module and ensure all code is compatible with PHP 8.1.<br>
- Add a PHPStan test to continuously verify PHP version compatibility.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>- Fix up existing PHP version conflicts.<br>
- Add a test to verify PHP version compatibility.</p>
issue