On Tuesday, October 16, 2018 at 2:26:51 AM UTC-5, Jan Schneider wrote:
>
> Zitat von Tyson Andre <[email protected] <javascript:>>:
>
> Earlier discussion about including this in PSR-5 is found in 
> https://github.com/phpDocumentor/fig-standards/issues/153 , I'm 
> re-opening the discussion here. 
>  
> This shorthand isn't part of the PSR-5 draft : 
> https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#abnf
>  
> Reasons:
>  
> - Nullable types are part of the language syntax for real signatures, so 
> adding this in PHPDoc makes some sense
> - @return ?string is shorter than @return string|null
> - Many static analyzers support this syntax in PHPDoc already 
> (Phan/Psalm/PHPStan (and phpdocumentor3 will?)).
>  
> Questions that were already brought up:
>  
> - A canonical way to represent the union type after parsing it in union 
> types - ?int|string, ?(int|string), ?int|?string, int|string|null are 
> equivalent, but which should be preferred for the output of tools
>   (not sure if that would need to be part of the standard)
> - Operator precedence (e.g. ?string[]) - I suggested treating that as 
> ?(string[]), others suggested forbidding ambiguous cases and forcing phpdoc 
> authors to add brackets - either explicitly write (?string)[] or 
> ?(string[]).
>
> For the sake of unambiguousity I'd prefer the latter, i.e. forcing to use 
> brackets. This would also solve the first question.
> ------------------------------
> Jan Schneider
> The Horde Project
> https://www.horde.org/
>


Normally I lean toward more explicit too.  In the case of nullable, though, 
I can concede that the more concise "just `?` at the beginning" could be 
good enough.  Presumably, if the first datatype in a union is allowed to be 
nullable, then *all* datatypes in the union list *have* to be considered 
nullable... right? 

@param string|array|\DateTime|null $arg

It wouldn't be reasonable to say "string can be null, but array can't be", 
because if you pass a null, then what datatype are you saying you are 
nulling? :-D

Based on this thinking, I can see just having a single `?` prefix without 
brackentheses (TM), at least not needing the wrapper to denote scope of the 
`?`.

Scope on a trailing `[]` in a union list... that's another story :-D
CRB

-- 
You received this message because you are subscribed to the Google Groups "PHP 
Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/php-fig/e4055f1a-995a-4f2a-a39d-f3b1b7468b48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to