@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);

}

```

0
5 comments

How about values from Generator->getReturnValue()? It's really useful when I use `yield from` all the time.

0

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.

0

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();`.

0

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

0

Please sign in to leave a comment.