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
 [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

Pull Requests

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: Sat Dec 21 12:01:31 2024 UTC