I'm in favor of @param DateIntervals ...$interval
Additionally, I'd be in favor of treating the union type differently based
on whether or not "..." was before the variable in the phpdoc
/** @param DateInterval[] $intervals this supports legacy syntax */
function example(DateInterval ...$intervals) {}
/** @param DateIntervals ...$intervals this supports newer uses. I'm in
favor of it because the phpdoc and real signature snippets are the same. */
function example(DateInterval ...$intervals) {}
A large number of tools expect "@param DateInterval ...$intervals" right
now. I'm not aware of tools that expect @param DateInterval[] ...$intervals
(with
both [] and ... simultaneously) but they'd be relevant to this discussion.
- phpStorm: https://youtrack.jetbrains.com/issue/WI-29429 (Marked as a
fixed+verified usability problem)
-
phan:
https://github.com/phan/phan/wiki/Frequently-Asked-Questions#a-variadic-function-with-phpdoc-has-unexpected-types
-
psalm:
https://github.com/vimeo/psalm/blob/2.0.14/tests/VariadicTest.php#L68-L91
(providerFileCheckerValidCodeParse provides file contents and asserts that
psalm doesn't warn about those
- phpstan: https://github.com/phpstan/phpstan/issues/683
- phpdocumentor: Couldn't find documentation - Possibly waiting for PSR-5
to be finalized? The implementation/tests may have changed
since
https://github.com/phpDocumentor/phpDocumentor2/issues/629#issuecomment-38902224
On Monday, October 15, 2018 at 6:55:40 PM UTC-4, Daniel Hunsaker wrote:
>
> Any reason not to consider another variant which may be clearer than
> either of the current proposals? For example:
>
> * @param DateInterval[...] $intervals
>
> This syntax indicates the value is an array, but is generated as such from
> a variadic list, rather than passing an actual array. That then allows
> support for something like the following to clearly address Stefano's
> scenario, above:
>
> * @param DateInterval[][...] $intervals
>
> I understand that the elipsis alone indicates a variadic list of arguments
> will be passed into the function/method as an array for PHP's sake, but
> documentation is for humans (and IDEs to a lesser degree), so deviating
> from it slightly in this way seems reasonable, at least to this particular
> human.
>
> - Dan Hunsaker
>
> On Mon, Oct 15, 2018, 14:41 Larry Garfield <[email protected]
> <javascript:>> wrote:
>
>> On Mon, Oct 15, 2018, at 3:46 PM, Chuck Burgess wrote:
>> > The current draft does not contain references to or examples of
>> variadic
>> > parameters, since they entered the PHP language after the early PSR-5
>> > drafts were done. Assuming that folks agree that they should be
>> > represented in the spec, this email thread opens the discussion on the
>> > syntax to use.
>> >
>> > Previous discussion exists here
>> > (https://github.com/phpDocumentor/fig-standards/issues/121), for
>> background
>> > reading.
>> >
>> > The key question on syntax is not whether to include "..." in the spec,
>> but
>> > with whether or not "[]" should also be shown:
>> >
>> > * @param DateInterval[] ...$intervals
>> >
>> > vs
>> >
>> > * @param DateInterval ...$intervals
>> >
>> > Both are meant to imply that the variable number of parameters passed
>> can
>> > be expected to be found inside an $intervals array of DateInterval
>> objects.
>> >
>> > Please reply to this thread with thoughts on this...
>> > CRB
>>
>>
>> I would say yes, include the []. That indicates "this thing is an array
>> of
>> these thingies", making it consistent with the same usage on
>> non-variadics.
>>
>> (Unless there's some later development that would make it conflict, or
>> it's
>> decided to reuse the syntax for something else, but for now, include the
>> [].)
>>
>> --Larry Garfield
>>
>> --
>> 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] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/php-fig/1539639684.104789.1543072184.166A0219%40webmail.messagingengine.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
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/25e26295-d946-44d4-8340-9bfe7a501e50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.