Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jenswegar opened this issue Jul 7, 2021 · 3 comments · Fixed by #4327
Closed

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

jenswegar opened this issue Jul 7, 2021 · 3 comments · Fixed by #4327

Comments

@jenswegar
Copy link
Contributor

jenswegar commented Jul 7, 2021

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.

@pabloveintimilla
Copy link

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

With this change work in php8

@MatrixOfDeath
Copy link

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

neclimdul added a commit to neclimdul/drupal-console that referenced this issue Feb 10, 2022
Fix hechoendrupal#4310

Since the later arguments are required this should be all that's needed.
LOBsTerr pushed a commit that referenced this issue Sep 15, 2022
Fix #4310

Since the later arguments are required this should be all that's needed.
@LOBsTerr
Copy link
Member

Thank for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment