Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The line $version = str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version']);
can cause deprecations in PHP 8.1 because $modules[$dependency]->info['version']
can be a NULL value.
Steps to reproduce
See test runs in #3220021: [meta] Ensure compatibility of Drupal 9 with PHP 8.1 (as it evolves)
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#13 | 3239287-2-13.patch | 4.46 KB | alexpott |
#13 | 3239287-2-13.test-only.patch | 3.67 KB | alexpott |
#13 | 11-13-interdiff.txt | 2.09 KB | alexpott |
#11 | 3239287-2-11.patch | 2.97 KB | alexpott |
| |||
#11 | 3239287-2-11.test-only.patch | 2.01 KB | alexpott |
Comments
Comment #2
alexpottHere's the fix from the meta issue.
I think this fix is okay while ->info is a dynamically set variable on the Extension class. Hopefully someday it will an ExtensionInfo object or something more elegant.
Comment #3
alexpottGoing to make this a duplicate of #3239295: Passing NULL to the $replace parameter of str_replace() and preg_replace() triggers a deprecation in PHP 8.1 and handle all deprecations due to str_replace() in the same issue.
Comment #4
alexpottDe-scoped this from #3239295: Passing NULL to the $replace parameter of str_replace() and preg_replace() triggers a deprecation in PHP 8.1 in order to work out why this is happening...
Comment #5
alexpottI'm not sure this change is necessary we don't seem to be hitting the exception - I've triggered a PHP 8.1 run without this change on the meta issue - see https://www.drupal.org/pift-ci-job/2190498
Comment #6
alexpottI'm pretty sure that this change is not needed given the results on the meta issue. Going to close this one.
Comment #7
alexpottThis is blocking contrib testing. See https://www.drupal.org/pift-ci-job/2261587 for an example from Search API. If a module is obtained via git or composer and the git_deploy or composer_deploy modules are not available then Drupal will not have the version info and it will be NULL which will cause a deprecation to be triggered.
Comment #8
alexpott#2 remains the simplest thing to do here which preserves the current PHP 8.0 and below behaviour and behaves the same way on PHP 8.1 without the deprecations. The reason core does not trigger this is because all core modules have VERSION as the version string.
Comment #9
andypostQueued test only patch for 10.x and PHP 8.1
Comment #10
longwaveThere are plenty of .info.yml in core that don't contain a version line already, e.g. core/modules/system/tests/modules/advisory_feed_test/advisory_feed_test.info.yml
Maybe this only triggers for modules outside the Testing package or something like that?
Comment #11
alexpottAh I see we need the module dependency system to kick in. Let's do this we modules being added to the site instead of core.
Comment #13
alexpottFound another place where we have exactly the same code that we need to fix in the same way. See system_requirements()
Comment #14
longwaveOh it would be so nice to have proper value objects instead of arrays :)
I looked for various combinations of info and version and can't find anything else that would cause a similar compatibility warning so I think this is RTBC.
Comment #17
catchCommitted/pushed to 10.0.x and cherry-picked to 9.4.x and 9.3.x, thanks!
Comment #19
longwaveDid a double-take at the test results here, but it turns out the fail on PHP 8.1 in 3239287-2-13.patch is an unrelated random JavaScript fail.
Comment #20
ressa CreditAttribution: ressa at Ardea commentedI just ran into this, #3255175: [D9 PHP 8.1] Deprecated function: str_replace(): Passing null to parameter ... on Extend and Status page. Thanks for fixing it :)
Comment #22
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks for doing this, however, there is still one more to fix. The same ?? correction also needs to be done in the ModuleDependencyMessageTrait 'incompatible with' return message. The test module's dependency just has the module name dependency_test but no version. So I am guessing that
!$dependency_object->isCompatible($version)
is not true in the test case, and the message is not displayed.If a version is given for the required module, then the condition will be true and the message is displayed, and php8.1 complains again that the string is null. I discovered this in a site where the required module was a git repo and so have no explicit version in .info.yml
Instead of re-opening this issue I will start a new one, and refer back to here? I will expand the test coverage to try to demonstrate the failure.
Comment #23
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedAdded the follow-up #3310555: ModuleDependencyMessageTrait - htmlspecialchars(): Passing null to parameter #1 is deprecated