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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 14:01:30 2024 UTC