php.net |  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:
MUST BE VALID
Solve the problem:
13 - 9 = ?
Subscribe to this entry?

 
 [2018-04-03 17:06 UTC] samuel dot roze at gmail dot com
Description:
------------
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:
https://gist.github.com/sroze/2ed22483b5fd35081b4fa31f02fd1a24#file-bug-example-php

Test script:
---------------
https://gist.githubusercontent.com/sroze/2ed22483b5fd35081b4fa31f02fd1a24/raw/b91b113e48f4730358fe75a4661bd5531b553d14/bug-example.php

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


Actual result:
--------------
Got exception do nothing
Got message test3


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-03 17:24 UTC] kelunik@php.net
-Status: Open +Status: Not a bug
 [2018-04-03 17:24 UTC] kelunik@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC