-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Mention nullable types in PSR-5 draft for phpdoc? (e.g. @param ?string $x
)
#153
Comments
Since nullable types are now part of the language syntax, I think it makes sense for the spec to add it as well. Having the Ping @ondrejmirtes @muglug @neuro159 @mindplay-dk @GaryJones @mvriel @jaapio for opinions. |
The current implementation of the type resolver that we wrote for phpdocumentor3 supports nullables. It is a language feature that should be available in the docblocks. I don't see any issues to keep both in the standard format. |
Agree! |
How does |
|
In the case of So, But based on my first point, If this is all correct, then presumably we can establish the |
I'll make PhpStorm to accept |
I'd hope that implementations would accept any input (e.g. Ideas:
Aside: Unfortunately, Phan currently represents it as |
I think the From that point of view I think it depends on the settings of the users project what a ide should generate. Pre php 7.1 should not use However I'm not sure if phpstorm is already able to detect the multiple types? I can't remember since I don't like the multi type inputs. But that is up to you. |
@jaapio I was the one who had to invent them exactly because of "@return string or false" ppl used to write... @TysonAndre braces - like this |
On the surface, I'd agree that However, it does visually remind the reader that the |
Nope 😄
Of Likewise, if I have So, I'd vote for |
We somewhat have a |
Thanks for bringing it out! |
(EDITED: operator listing) Ok, so we're talking about using order of precedence with regard to operators. If we can use the same order in all places where the various operator characters are used, we can outline the precedence in an appendix.
We can probably highlight at the same time that using |
I would strongly advice against relying on people remembering the correct precedence of most operators and instead suggest disallowing most ambiguous formats. For example all of the following are explicitly disallowed by PHPStan to avoid confusion.
The following is allowed for historical reasons
(See ABNF grammar for more precise description) |
@TysonAndre , if you wish to pursue this further, please bring this up as a new thread on the FIG mailing list for discussion -- https://groups.google.com/forum/#!forum/php-fig |
Currently, the phpdoc2 standard says nothing about nullable types (
?string
), and would suggest writing it asstring|null
instead.I don't see any open PRs or issues mentioning "nullable"
Questions:
(I find
@param ?string $x
much more convenient to use than@param string|null $x
, and it's consistent with the way a real type would be written.)Background:
Issues to consider when implementing this:
?string[]
that should be addressed in a standard. One way to resolve this is to parse it as?(string[])
, and require(?string)[]
or(string|null)[]
to indicate arrays of nullable strings.(And maybe to reject
??T
without brackets)The text was updated successfully, but these errors were encountered: