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
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
Comment #2
chuck_theobald commentedComment #3
garvitasakhrani commentedI am working on it.
Comment #5
garvitasakhrani commentedFixed 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.
Comment #6
garvitasakhrani commentedComment #7
chuck_theobald commentedI'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.
Comment #8
chuck_theobald commentedI am sorry, but I cannot apply the patch to the Dubbot 2.0 version. I get composer errors:
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:
Comment #9
chuck_theobald commentedOkay, 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.
Comment #10
betoaveigaI 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)) {
```
Comment #11
vinodhini.e commentedHi,
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.
Comment #12
deviantintegral commentedI fixed this in #3619054 since CI jobs failed on this too. I'll get a new release out later this week. Thank you!