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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: samuel dot roze at gmail dot com
New email:
PHP Version: OS:

 

 [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-2021 The PHP Group
All rights reserved.
Last updated: Tue Nov 30 10:03:35 2021 UTC