php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69740 finally in generator (yield) swallows exception in iteration
Submitted: 2015-06-01 15:30 UTC Modified: 2015-06-01 15:35 UTC
From: markus at malkusch dot de Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.6.9 OS: Linux
Private report: No CVE-ID: None
 [2015-06-01 15:30 UTC] markus at malkusch dot de
Description:
------------
From https://wiki.php.net/rfc/generators I learned that finally blocks are valid in Generators:

> If the generator contains (relevant) finally blocks those will be run.

When I iterate over such a generator and would throw an exception the exception seems to be swallowed. This behaviour was introduced in PHP-5.6 as it worked in PHP-5.5 as I would expect it: http://3v4l.org/QX4qP

I can't tell if this is related to https://bugs.php.net/bug.php?id=62210.

Test script:
---------------
<?php

function generate()
{
    try {
        yield 1;
        yield 2;

    } finally {
        echo "finally\n";
    }
}

foreach (generate() as $i) {
    echo $i, "\n";
    throw new Exception();
}


Expected result:
----------------
1
finally
Fatal error: Uncaught exception 'Exception'

Actual result:
--------------
1
finally

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-01 15:35 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2015-06-01 15:35 UTC] nikic@php.net
Finally handling changed a lot in PHP 5.6, probably some change was not propagated to the generators implementation.
 [2015-06-11 15:45 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8405265578d2df8d76be223910b3e44aff4bdfef
Log: Fix bug #69740
 [2015-06-11 15:45 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2015-06-23 18:04 UTC] ab@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8405265578d2df8d76be223910b3e44aff4bdfef
Log: Fix bug #69740
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC