[PHP 8.4] Fixes for implicit nullability deprecation
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.
just came here to submit a similar PR. would be great to have this one merged :-)
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)
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 .= ' ';
}
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)