drupal-console
drupal-console copied to clipboard
[console] PHP warning in DrupalServiceModifier when commands called on PHP8
Problem/Motivation
PHP8 outputs a notice for methods that define optional arguments before required arguments (https://php.watch/versions/8.0/deprecate-required-param-after-optional).
In Drupal\Console\Bootstrap\DrupalServiceModifier
, the first argument to the constructor defines a default value as null.
How to reproduce
- Drupal version: 9.1.10
- Console version: 1.9.7
Run any console command on a php8 installation. E.g.
- download and run docker image of Drupal 9.1
- install drupal-console using composer
- attempt to call drupal list.
- before the list command gets executed, the following notification is output:
<em class="placeholder">Deprecated function</em>: Required parameter $serviceTag follows optional parameter $root in <em class="placeholder">include()</em> (line <em class="placeholder">480</em> of <em class="placeholder">/opt/drupal/vendor/composer/ClassLoader.php</em>). <pre class="backtrace">include() (Line: 480)
Composer\Autoload\includeFile('/opt/drupal/vendor/composer/../drupal/console/src/Bootstrap/DrupalServiceModifier.php') (Line: 346)...<snip for brevity)
Solution
Remove the default value assignment for the first parameter.
The same problem are in drupal console v1.9.7, I have patched these files:
- /vendor/drupal/console-core/src/Bootstrap/DrupalConsoleCore.php: Patch: DrupalConsoleCore.php.txt
- /vendor/drupal/console-core/src/Utils/NestedArray.php. Path: NestedArray.php.txt
With this change work in php8
Is drupal/console with drush 10+ and drupal9.3 compatible with PHP8.x ?
Thank for your contribution