Problem/Motivation

With a website updated to use PHP 8.4, PHP will issue warnings about "Implicitly marking parameter <$parameter> as nullable is deprecated, the explicit nullable type must be used instead in ..." when loading a module with such parameters declared. Warning messages will appear to logged in users. I do not think these appear to anonymous website visitors.
For example:
Deprecated: Drupal\dubbot\DubBotEmbedJsonResponse::__construct(): Implicitly marking parameter $page_id as nullable is deprecated, the explicit nullable type must be used instead in /code/web/modules/contrib/dubbot/src/DubBotEmbedJsonResponse.php on line 6

Steps to reproduce

Install and enable the DubBot module, version 1.x or 2.x. Log in and navigate to trigger a load of the module. Warning messages will appear below the admin toolbar area.

Proposed resolution

Update code to incorporate changes in the "Recommended Changes" section of:
https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullabl...

The simplest approach is to add a "?" in front of the type declaration. Such declarations are present in version 2.x files:

  • ./src/Client.php
  • ./src/DubBotEmbedJsonResponse.php

Remaining tasks

n/a

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Issue fork dubbot-3565759

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

chuck_theobald created an issue. See original summary.

chuck_theobald’s picture

Issue summary: View changes
garvitasakhrani’s picture

Assigned: Unassigned » garvitasakhrani

I am working on it.

garvitasakhrani’s picture

Status: Active » Needs review

Fixed PHP 8.4 implicit nullable parameter deprecation warnings by explicitly marking nullable type hints.
Changes pushed to issue fork branch 3565759-php-8.4-deprecation.
Please review.

garvitasakhrani’s picture

Assigned: garvitasakhrani » Unassigned
chuck_theobald’s picture

I'm trying to review this, unsure how to get it working on my Pantheon hosted dev/test environment. Will continue my researches into how to check out this fork branch.

chuck_theobald’s picture

I am sorry, but I cannot apply the patch to the Dubbot 2.0 version. I get composer errors:

   Could not apply patch! Skipping. The error was: Cannot apply patch https://git.drupalcode.org/project/dubbot/-/merge_requests/14.patch

In Patches.php line 331:

  Cannot apply patch Fix PHP 8.4 implicit nullable parameter deprecation (https://git.drupalcode.org/project/dubbot/-
  /merge_requests/14.patch)!

How can I apply garvitasakhrani's patch to my test site?

FYI, I have cweagans/patches installed and have added this to my composer file:

+    "patches": {
+      "drupal/dubbot": {
+        "Fix PHP 8.4 implicit nullable parameter deprecation" : "https://git.drupalcode.org/project/dubbot/-/merge_requests/14.patch"
+      }
+    },
chuck_theobald’s picture

Okay, got it sorted. My system did not have a native patch utility installed. Once installed, the patch was applied and I pushed it to my Dev machine. I am not getting the "implicit nullable parameter deprecation" warnings, so I think the patch is good to be merged.

betoaveiga’s picture

I made this patch with AI in case you find it useful.
It is for version 2.0.2

```
--- a/src/Client.php
+++ b/src/Client.php
@@ -129,7 +129,7 @@
* @return string|null
* The endpoint URL for the given path. NULL if unable to build it.
*/
- protected function buildUrl(string $path, array $query = [], string $embed_key = NULL): ?string {
+ protected function buildUrl(string $path, array $query = [], ?string $embed_key = NULL): ?string {
if (!isset($embed_key)) {
$embed_key = $this->dubbotEmbedKey();
if (empty($embed_key)) {
```

vinodhini.e’s picture

Hi,

Tested on Drupal 11.3.11 with PHP 8.4.

I was able to reproduce the reported deprecation warning. After applying the MR #14 and retesting, the deprecation notice was no longer displayed.

Thanks.

deviantintegral’s picture

Status: Needs review » Fixed

I fixed this in #3619054 since CI jobs failed on this too. I'll get a new release out later this week. Thank you!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.