@yield? in generators phpdoc
How do you define the type a generator yields? is there a @yield?
```
/**
* generator for integers in a range
* @param int $from
* @param int $to
* @return Generator
* @yield int
*/
function yrange(int $from, int $to)
{
$value = $from;
do { yield $value++; } while ($value <= $to);
}
```
Please sign in to leave a comment.
Hello,
@return should be used with generators.
https://twitter.com/phpdocumentor/status/422617412283158528
https://stackoverflow.com/questions/30083184/best-way-to-document-phpdoc-generators-methods-that-yield
How about values from Generator->getReturnValue()? It's really useful when I use `yield from` all the time.
Sofe2038, not really sure I got your question right. If you what to specify multiple return types, just fill them in separated by a pipe:
@return type1|type2|\Some\Type\Three.Tagging @return with an array type can only infer type for `$foo` in `foreach(generator_function() as $foo)`. I want to infer type for `$bar` in `$bar = yield from generator_function();`.
Oh, I see now. We could possibly infer the type from the function return annotation on
yield from. Please submit this as a feature request attaching a code sample: https://youtrack.jetbrains.com/newIssue?project=WI