|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76181 `yield`ed item is lost after sending an exception to the generator
Submitted: 2018-04-03 17:06 UTC Modified: 2018-04-03 17:24 UTC
From: samuel dot roze at gmail dot com Assigned:
Status: Not a bug Package: *Programming Data Structures
PHP Version: 7.2.4 OS: OSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
42 - 18 = ?
Subscribe to this entry?

 [2018-04-03 17:06 UTC] samuel dot roze at gmail dot com
When calling `throw($e)` on a Generator while iterating over it, it looks like it "lose" one of the items that have been `yield`ed.

See the following Gist:

Test script:

Expected result:
Got exception do nothing
Got message test2
Got message test3

Actual result:
Got exception do nothing
Got message test3


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-03 17:24 UTC]
-Status: Open +Status: Not a bug
 [2018-04-03 17:24 UTC]
This is not a bug. `Generator::throw()` advances the generator. The yielded value can be retrieved by examining the return value of `Generator::throw()`.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun May 28 13:03:46 2023 UTC