drupal-console icon indicating copy to clipboard operation
drupal-console copied to clipboard

[console] PHP warning in DrupalServiceModifier when commands called on PHP8

Open jenswegar opened this issue 2 years ago • 2 comments

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.

  1. download and run docker image of Drupal 9.1
  2. install drupal-console using composer
  3. attempt to call drupal list.
  4. 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(&#039;/opt/drupal/vendor/composer/../drupal/console/src/Bootstrap/DrupalServiceModifier.php&#039;) (Line: 346)...<snip for brevity)

Solution

Remove the default value assignment for the first parameter.

jenswegar avatar Jul 07 '21 07:07 jenswegar

The same problem are in drupal console v1.9.7, I have patched these files:

With this change work in php8

pabloveintimilla avatar Aug 16 '21 02:08 pabloveintimilla

Is drupal/console with drush 10+ and drupal9.3 compatible with PHP8.x ?

MatrixOfDeath avatar Dec 20 '21 00:12 MatrixOfDeath

Thank for your contribution

LOBsTerr avatar Sep 15 '22 09:09 LOBsTerr