Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP 8.4] Fixes for implicit nullability deprecation #441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ayesh
Copy link

@Ayesh Ayesh commented Mar 18, 2024

Fixes all issues that emit deprecation notices on PHP 8.4 for implicit nullable parameter type declarations.

See:

The changes are modified on the generated files. This PR is merely to show the diffs.

Fixes all issues that emit deprecation notices on PHP 8.4 for implicit nullable parameter type declarations.

See:
 - [RFC](https://wiki.php.net/rfc/deprecate-implicitly-nullable-types)
 - [PHP 8.4: Implicitly nullable parameter declarations deprecated](https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated)
@staabm
Copy link

staabm commented May 25, 2024

just came here to submit a similar PR. would be great to have this one merged :-)

@ophian
Copy link

ophian commented Aug 26, 2024

me too... 😅 I should have had a look earlier and it would have saved me an hour of work... (I did this to get rid of the deprecations in PhpMyAdmin)

@Ayesh Ayesh marked this pull request as ready for review August 29, 2024 01:33
@shish
Copy link

shish commented Sep 9, 2024

This is my current attempt at updating the generator to handle this case:

--- a/generator/src/Parameter.php
+++ b/generator/src/Parameter.php
@@ -75,7 +75,7 @@ class Parameter

     public function isNullable(): bool
     {
-        return $this->phpStanType->isNullable();
+        return $this->phpStanType->isNullable() || $this->getDefaultValue() === "null";
     }

     /*
diff --git a/generator/src/WritePhpFunction.php b/generator/src/WritePhpFunction.php
index d0775fb..ed4f11a 100644
--- a/generator/src/WritePhpFunction.php
+++ b/generator/src/WritePhpFunction.php
@@ -143,6 +143,9 @@ class WritePhpFunction
             }

             if ($paramAsString !== '') {
+                if ($param->isNullable() && $paramAsString[0] !== "?") {
+                    $paramAsString = "?" . $paramAsString;
+                }
                 $paramAsString .= ' ';
             }

@shish
Copy link

shish commented Sep 10, 2024

I needed this for my own use, and I don't see it getting merged any time soon, so I've fixed this (and merged a bunch of the other open PRs) and released as shish/safe (flagged as a replacement package so it should be drop-in compatible)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants