-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
void
vs. null
#176
Comments
Static analysis is about strict types. I am sorry. I consider PHP functions returning implicit null-s a language error. |
Wait!
Why do we have an extra condition in our code for phpstan-wordpress/src/EchoParameterDynamicFunctionReturnTypeExtension.php Lines 113 to 118 in 51a29b6
|
Because for |
I see! When title is an empty string. If that is the case one should always check whether the return value of |
So properly written code for WordPress is long, hard to understand and silly. sprintf('', the_title('<span>', '</span>', false) ?? '') |
No, this is not working. |
You healing or the code? |
There is no solution in PHP for detecting void. |
Me healing. |
Oh no! We love szepeviktor/phpstan-wordpress! |
We need a businessman who can let perfectionism go. 🎦 |
I was also annoyed already by the fact that See also https://phpstan.org/r/23820230-f5a3-4533-9543-79b453cd5bd8 But if they internally just do |
but wait, as @IanDelMar quoted in the beginning
and indeed it crashes spectacularly: https://3v4l.org/iRfF2 I wonder if PHPStan should be more strict with these invalid unions. Considering that PHPDoc is interpreted as it would be native type by default, the type is invalid IMO. I'll open a PHPStan issue. |
@johnbillion do you think we can change all those implicit null returns from |
Changing a Making those functions nullable instead of voidable sounds like a good idea. |
Okay. Let's go on with this good idea. |
The return type extension for |
Has anyone opened a ticket to get this into core? Or is planning to do so? |
fyi this is going to be dealt with here: phpstan/phpstan-src#2778 all |
I dream about WordPress not having string|void-s |
PHPStan v 1.10.50 has this feature. |
I think you can close this one, no? UPDATE: or maybe bump min PHPStan version and adapt tests if necessary? |
A bump may be necessary. |
Should we ditch
void
in the EchoKey and the EchoParameter extensions and usenull
instead? Technically there is no such thing as void in PHP. However, as of PHP 7.1.0 there is a void return type. The PHP manual saysIt also says
WordPress does use
void
in union types in doc blocks... which actually should be nullable return types. Seethe_title()
for an example. Having void as return type for these functions leads togiving
Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, string|void given.
thoughsprintf()
is completely fine withthe_title('<span>', '</span>', false)
as it is eitherstring
ornull
.I don't know why this didn't pop up earlier.
The text was updated successfully, but these errors were encountered: