Best way to document (phpdoc) generators (methods that yield)

Mat-Locomotive picture Mat-Locomotive · May 6, 2015 · Viewed 8.5k times · Source

What is the best way to document, for phpdocumentor2, a method that is a generator.

I don't think @return really works for yield, but I can't seem to find any proper alternative.

Is it just a matter of waiting for phpdoc to catch up?

Answer

Robbert picture Robbert · Apr 30, 2016

I went with @return Generator|SomeObject[], where SomeObject is the thing being yielded.

PhpStorm handles this well too, as it now normally hints Generator methods and when iterated it hints SomeObject methods.

(Still, I would prefer a native @yield.)