This is the issue traking the implementation on 
PHPStan: https://github.com/phpstan/phpstan/issues/652

Il giorno sabato 8 dicembre 2018 21:44:14 UTC+1, Chuck Burgess ha scritto:
>
> I'm thinking this use case will probably need to rely on some kind of 
> collection/generics syntax.  Do we know if PhpStorm / PHPStan / etc have 
> looked at syntaxes for this use case?
> CRB
> *about.me/ashnazg <http://about.me/ashnazg>*
>
>
> On Mon, Nov 12, 2018 at 11:38 AM Woody Gilk <woody.g...@gmail.com> wrote:
>
>> Could we use:
>>
>> @return iterable<int>
>>
>> ?
>>
>> Also generators can return key => value:
>>
>> @return iterable<int,User>
>>
>> Would imply:
>>
>> yield $key => $user;
>>
>> --
>> Woody Gilk
>> https://shadowhand.me
>>
>>
>> On Mon, Nov 12, 2018 at 11:34 AM Larry Garfield <la...@garfieldtech.com> 
>> wrote:
>>
>>> On Monday, November 12, 2018 10:06:08 AM CST Chuck Burgess wrote:
>>> > So here we do indeed have a special IDE implementation to try to deal 
>>> with
>>> > the OP's kind of use case.
>>> > 
>>> > Again, I can't envision a more standardized way to solve this with tags
>>> > themselves.
>>> > 
>>> > 
>>> > I'll mention this again, with regard to this use case though:
>>> > Stepping back a moment... that /* @var */ usage... seems like I've only
>>> > ever seen that used to typehint the $item portion of the example, not 
>>> the
>>> > $stream portion... $stream should have been figured out earlier when 
>>> it was
>>> > first populated, either by its own /* @var */ doc or by the return 
>>> type of
>>> > whatever function/method actually populated it.
>>> > 
>>> > Would using the /* @var */ in this manner not solve this use case?
>>> > CRB
>>> > *about.me/ashnazg <http://about.me/ashnazg>*
>>>
>>> I agree that, when putting a @var over a foreach, only the $item is 
>>> really 
>>> relevant to document.
>>>
>>> My use case may be tangential/related, as I'm talking more about how to 
>>> specify "iterable of X" in "the return type of whatever function/method 
>>> actually populated it".
>>>
>>> While it would be lovely to say that [] implies any "collection", I 
>>> don't 
>>> think PHP will let us do that.  Arrays and iterables are not 
>>> interchangeable, 
>>> as there's a few dozen functions that work on arrays but not iterables.
>>>
>>> To wit:
>>>
>>> /**
>>>  * @return int[]
>>>  */
>>> function foo() : iterable {
>>>
>>> }
>>>
>>> int[] implies "Array of ints", which means calling array_* functions on 
>>> it is 
>>> a totally legit thing to do.  But what's returned is an iterable, which 
>>> means 
>>> there's no guarantee that it's an array; it could return any 
>>> Traversable, or 
>>> foo() could be a generator itself.  In those cases, the docblock is now 
>>> materially wrong and misleading.
>>>
>>> I'm not sure what the best solution here is, but I do think we need one.
>>>
>>> (And that's before we get into the excitement of an iterable that 
>>> returns non-
>>> numeric keys, which is also completely valid, so we have to think about 
>>> something like Go maps, yeaaaaaahhhh!)
>>>
>>> --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 php-fig+unsubscr...@googlegroups.com.
>>> To post to this group, send email to php-fig@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/php-fig/39547303.NTl641kpUQ%40vulcan.
>>> 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 php-fig+unsubscr...@googlegroups.com.
>> To post to this group, send email to php-fig@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/php-fig/CAGOJM6%2BV8Da%3Dc_%3Di2Rq%3D5Vq8uQ6%2BvX7sdnoVeq%2BKZde5of7DEg%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/php-fig/CAGOJM6%2BV8Da%3Dc_%3Di2Rq%3D5Vq8uQ6%2BvX7sdnoVeq%2BKZde5of7DEg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> 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 php-fig+unsubscr...@googlegroups.com.
To post to this group, send email to php-fig@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/php-fig/a42101d4-1b94-47f2-9304-6cc890a96abf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to