Bug #69740 [NEW]: finally in generator (yield) swallows exception in iteration
| From: | markus at malkusch dot de | Date: | Mon, 01 Jun 2015 15:30:09 +0000 |
| Subject: | Bug #69740 [NEW]: finally in generator (yield) swallows exception in iteration | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-193051@lists.php.net to get a copy of this message | ||
From: markus at malkusch dot de
Operating system: Linux
PHP version: 5.6.9
Package: Scripting Engine problem
Bug Type: Bug
Bug description:finally in generator (yield) swallows exception in iteration
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
--
Edit bug report at https://bugs.php.net/bug.php?id=69740&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69740&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69740&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69740&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69740&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69740&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69740&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69740&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69740&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69740&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69740&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69740&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69740&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69740&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69740&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69740&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69740&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69740&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69740&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69740&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69740&r=mysqlcfg