PSR-5: @throws tags on generator syntax

32 views
Skip to first unread message

Andreas Hennings (donquixote)

unread,
Oct 11, 2019, 9:22:42 AM10/11/19
to PHP Framework Interoperability Group
Hello list!
I have a comment about the @throws tag. I think this would be part of the PSR-5 discussion.


## Background

On a generator function (a function with "yield" statement), a @throws tag has a special meaning:
- Calling the function itself will NOT throw an exception.
- Calling ->current(), ->valid() or ->next() on the returned object might throw an exception.

On a function with "@return \Iterator" or "@return \Traversable", which is not itself a generator, a @throws tag can mean both:
- The function itself might throw an exception.
- The ->current(), ->valid() or ->next() on the returned object might throw an exception.


## Question

Do we need a different kind of @throws tag for generators?
Or do we simply live with the ambiguity?
Or should a @throws tag be omitted if it does not apply to the function itself?


## See also

The question came up when discussing the inspection behavior in PhpStorm,

The @throws tag is currently documented here,


-- Andreas
Reply all
Reply to author
Forward
0 new messages