Fix PHP 8.4 implicit nullable deprecation

Created on 22 November 2024, 8 months ago

Problem/Motivation

PHP 8.4 has been released, and this module is triggering a "use explicit nullable type" deprecation.

This is part of Drupal's coding standards now, but since the issues to fix phpcs in this module have stalled, I'm opening up this issue to fix this single deprecation to avoid the warnings on PHP 8.4.

After updating to PHP 8.4:

Deprecated: Drupal\pathauto\Commands\PathautoCommands::generateAliases(): Implicitly marking parameter $types as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/pathauto/src/Commands/PathautoCommands.php on line 89
PHP Deprecated:  Drupal\pathauto\Commands\PathautoCommands::deleteAliases(): Implicitly marking parameter $types as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/pathauto/src/Commands/PathautoCommands.php on line 135

Deprecated: Drupal\pathauto\Commands\PathautoCommands::deleteAliases(): Implicitly marking parameter $types as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/pathauto/src/Commands/PathautoCommands.php on line 135
PHP Deprecated:  Drupal\pathauto\AliasStorageHelper::__construct(): Implicitly marking parameter $entity_type_manager as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/pathauto/src/AliasStorageHelper.php on line 79

Deprecated: Drupal\pathauto\AliasStorageHelper::__construct(): Implicitly marking parameter $entity_type_manager as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/pathauto/src/AliasStorageHelper.php on line 79
PHP Deprecated:  Consolidation\AnnotatedCommand\State\StateHelper::injectIntoCallbackObject(): Implicitly marking parameter $output as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/vendor/consolidation/annotated-command/src/State/StateHelper.php on line 20
🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇯🇵Japan ptmkenny

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ptmkenny
  • Merge request !91fix implicit nullable deprecations → (Open) created by ptmkenny
  • Pipeline finished with Success
    8 months ago
    #346642
  • 🇮🇳India prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan

    I have reviewed the MR !91 and its working fine after upgrade to the php 8.4 version.

  • Status changed to RTBC 6 months ago
  • 🇩🇰Denmark ressa Copenhagen

    Thanks for working on this, tagging with PHP 8.4, to easier follow along.

  • 🇦🇹Austria klausi 🇦🇹 Vienna

    Uploading stable patch file for composer patches.

  • is the patch included now ? because ma getting some warnings regarding same issue
    Drupal version = 11.1.7
    pathauto version = 8.x-1.13
    php version = 8.4.7

    
    Deprecated function: Drupal\pathauto\AliasStorageHelper::__construct(): Implicitly marking parameter $entity_type_manager as nullable is deprecated, the explicit nullable type must be used instead in include() (line 576 of /var/www/html/drpee/vendor/composer/ClassLoader.php).
    
    include() (Line: 576)
    {closure:Composer\Autoload\ClassLoader::initializeIncludeClosure():575}() (Line: 427)
    Composer\Autoload\ClassLoader->loadClass() (Line: 259)
    Drupal\Component\DependencyInjection\Container->createService() (Line: 177)
    Drupal\Component\DependencyInjection\Container->get() (Line: 430)
    Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)
    Drupal\Component\DependencyInjection\Container->createService() (Line: 177)
    Drupal\Component\DependencyInjection\Container->get() (Line: 75)
    Drupal\pathauto\Form\PathautoSettingsForm::create() (Line: 36)
    Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (Line: 48)
    Drupal\Core\Controller\HtmlFormController->getFormObject() (Line: 58)
    Drupal\Core\Controller\FormController->getContentResult()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::wrapControllerExecutionInRenderContext():121}() (Line: 593)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::onController():96}() (Line: 183)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 709)
    Drupal\Core\DrupalKernel->handle() (Line: 19)
    
    
    
  • 🇩🇪Germany hosterholz

    MR !91 works.
    RTBC+1

    @#7 This issue is not fixed yet.

  • First commit to issue fork.
  • 🇫🇷France pbonnefoi

    I had the same error as @#7 and fixed it with my commit.

  • Pipeline finished with Success
    5 days ago
    Total: 176s
    #542886
  • 🇯🇵Japan ptmkenny

    @pbonnefoi Please explain what "the same error as #7" means-- #7 did not apply the MR. Your commit breaks backward compatibility because it changes the acceptable argument type by removing null. I think this is an unnecessary change and out of scope for this issue; please explain why the change is necessary.

  • 🇫🇷France pbonnefoi

    Well, sorry my comment was redacted having few little times (working actively on updating a project from D10 to D11). And indeed I misread the warning from #7
    I had a resembling warning using Drupal 11.2 / PHP 8.4 :
    Drupal\pathauto\PathautoGenerator::__construct(): Implicitly marking parameter $alias_type_manager as nullable is deprecated, the explicit nullable type must be used instead.

    Looking at the code I found that in PathautoGenerator, the service was loaded using \Drupal::service('plugin.manager.alias_type') if NULL. That does not make sense to me as it is loaded with DI within pathauto.services.yml. But maybe I'm missing something in the picture.

    Though I think the fix should be just having ?AliasTypeManager $alias_type_manager = NULL at least.

    Please let me know if I can help somehow.

  • Pipeline finished with Success
    3 days ago
    Total: 200s
    #544845
  • 🇯🇵Japan ptmkenny

    Setting back to RTBC based on #4 and #7, and the change in #9 was reverted.

    @pbonnefoi Yes, the service should generally be auto-loaded, but since the constructor accepts NULL, we have to handle the case of a NULL value, since that is the API argument. To preserve BC, eliminating the NULL argument can only happen in a module major version update.

Production build 0.71.5 2024