Problem/Motivation

In PHP 8.4, declaring functions/methods with parameters containing null as a default value, but without null as one of the types (either as a nullable syntax or as a Union type with null) is deprecated.

https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullabl...

Steps to reproduce

core/modules/contrib/default_content$ ../../../vendor/bin/phpcs --standard=SlevomatCodingStandard --sniffs=SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue .

FILE: /home/andypost/www/core/modules/contrib/default_content/src/ContentFileStorage.php
---------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------
 67 | ERROR | [x] Parameter $filename has null default value, but is not marked as nullable.
---------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------


FILE: /home/andypost/www/core/modules/contrib/default_content/src/ContentFileStorageInterface.php
-------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------
 36 | ERROR | [x] Parameter $filename has null default value, but is not marked as nullable.
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------


FILE: /home/andypost/www/core/modules/contrib/default_content/src/Importer.php
-------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------
 159 | ERROR | [x] Parameter $file_system has null default value, but is not marked as nullable.
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------

Time: 420ms; Memory: 14MB

Proposed resolution

Update all instances of such declarations to use Union types or nullable types.

This is a rather big set of changes. To replicate the results:

cd core
../vendor/bin/phpcbf --standard=SlevomatCodingStandard --sniffs=SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue lib modules themes profiles tests

or
php-cs-fixer fix . --rules nullable_type_declaration_for_default_null_value

Add SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue sniffer to prevent new issues

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

andypost created an issue. See original summary.

andypost’s picture

Status: Active » Needs review

Tests show it's ready

andypost’s picture

Status: Needs review » Reviewed & tested by the community

the patch is trivial, commiting

  • andypost committed b85c0192 on 2.0.x
    Issue #3470061 by andypost: [PHP 8.4] Fix implicitly nullable type...
andypost’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

rajab natshah’s picture

Thank you for this fix.
Hoping for a release.

rajab natshah’s picture

Priority: Normal » Major