-
Notifications
You must be signed in to change notification settings - Fork 659
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
trait_exists()
returns nullable value, according to psalm stubs
#7478
Comments
I found these snippets: https://psalm.dev/r/c41a43805d<?php
function traitDoesIndeedExist(string $traitName): bool
{
return trait_exists($traitName);
}
|
The documentation is contradictory, it gives a return type of I don't know how to read PHP's source with all it's preprocessor stuff well enough to say for sure, but I think this might have changed for PHP 7. I would guess that this would cause a |
Here's a case where it returns null for PHP < 8.0: https://3v4l.org/XpHmh. |
Indeed, assuming the function is defined as having 2 parameters, then |
We don't. Psalm has a policy of ignoring ZPP nulls like that. |
We have an unofficial rule where any type returned only when the params are wrong (and are reported by Psalm) can be ignored in our callmaps to avoid cluttering |
Well, I think we can safely fix that in callmaps. Anyone want to create the PR? :) |
Fixes vimeo#7478 As discussed in the upstream issue, `trait_exists()` always returns `bool`: while it can return `null` when the arguments passed to it do not match (either no arguments, or 3 or more arguments), we do not support that scenario, as that already doesn't respect the type signature of this function. We cut to the point: always make it `bool`, which is the scenario that works under healthy operational conditions. Ref: Roave/BetterReflection#983 (comment) Ref: https://psalm.dev/r/c41a43805d Ref: vimeo#7478 (comment) Ref: vimeo#7478 (comment) Ref: https://3v4l.org/XpHmh
Fixes vimeo#7478 As discussed in the upstream issue, `trait_exists()` always returns `bool`: while it can return `null` when the arguments passed to it do not match (either no arguments, or 3 or more arguments), we do not support that scenario, as that already doesn't respect the type signature of this function. We cut to the point: always make it `bool`, which is the scenario that works under healthy operational conditions. Ref: Roave/BetterReflection#983 (comment) Ref: https://psalm.dev/r/c41a43805d Ref: vimeo#7478 (comment) Ref: vimeo#7478 (comment) Ref: https://3v4l.org/XpHmh
@orklah sorry, took me a while to actually get to clone + change the file (github editor does not allow for that anymore, due to its size :D ) |
Fixes vimeo#7478 As discussed in the upstream issue, `trait_exists()` always returns `bool`: while it can return `null` when the arguments passed to it do not match (either no arguments, or 3 or more arguments), we do not support that scenario, as that already doesn't respect the type signature of this function. We cut to the point: always make it `bool`, which is the scenario that works under healthy operational conditions. Ref: Roave/BetterReflection#983 (comment) Ref: https://psalm.dev/r/c41a43805d Ref: vimeo#7478 (comment) Ref: vimeo#7478 (comment) Ref: https://3v4l.org/XpHmh
…returns-boolean Ensure `trait_exists()` always returns `bool`
JFTR: ZPP failures are not supposed to be documented in the PHP manual for each function/method; there is already a general clause regarding internal functions:
So yes, this is a php/doc-en bug, which has just been fixed. |
@cmb69 Thanks for the info, I'll report it next time I notice one. |
Ref: php/doc-en@de99fc7 Seems like nullability wasn't documented in the docbook types, but just in the description. |
@Ocramius, the signatures are autogenerated from the stub files now, but occassionally related changes in other parts of the docs are overlooked. |
See Roave/BetterReflection#983 (comment)
See https://psalm.dev/r/c41a43805d
In
vimeo/psalm:4.18.1
,trait_exists()
is declared astrait_exists(string): ?bool
: it should perhaps returnbool
at all time (not nullable).Produces
Definition seems to be imprecise in https://github.com/vimeo/psalm/blob/f1c4b62f5c65e887892e768dbaff6207ded14cee/dictionaries/CallMap.php
/cc @voku
The text was updated successfully, but these errors were encountered: