Bug #79657 [NEW]: "yield from" hangs when invalid value encountered
| From: | max dot tun at pm dot me | Date: | Sun, 31 May 2020 17:09:28 +0000 |
| Subject: | Bug #79657 [NEW]: "yield from" hangs when invalid value encountered | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-227255@lists.php.net to get a copy of this message | ||
From: max dot tun at pm dot me
Operating system: Alpine Linux
PHP version: 7.4.6
Package: *General Issues
Bug Type: Bug
Bug description:"yield from" hangs when invalid value encountered
Description:
------------
Starting from PHP 7.4.6 (I've managed to reproduce on 7.4.7RC1 as well)
"yield from" hangs when I try to unwrap generator into function
arguments and an invalid value is encountered or an exception is
thrown.
In the example provided this won't happen if the "get" function doesn't
have arguments.
This also doesn't happen if I unwrap the generator into an array.
Also, works as expected if an error occurs on first iteration.
The script hangs on line #15 and CPU usage and memory consumption
increases significantly, looks like there's an infinite loop.
Test script:
---------------
<?php
function throwException(): iterable
{
throw new Exception();
}
function loop(): iterable
{
$callbacks = [
function () {
yield 'first';
},
function () {
yield from throwException();
}
];
foreach ($callbacks as $callback) {
yield from $callback();
}
}
function get(string $first, int $second): array
{
return [];
}
get(...loop());
Expected result:
----------------
Either this if I throw an exception:
Fatal error: Uncaught Exception in test.php:5
Stack trace:
#0 test.php(15): throwException()
#1 test.php(20): {closure}()
#2 test.php(29): loop()
#3 {main}
thrown in test.php on line 5
Or the following if an invalid value is being used to yield from:
Fatal error: Uncaught Error: Can use "yield from" only with arrays and
Traversables in test.php:15
Stack trace:
#0 test.php(20): {closure}()
#1 test.php(29): loop()
#2 {main}
thrown in test.php on line 15
--
Edit bug report at https://bugs.php.net/bug.php?id=79657&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79657&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79657&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79657&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79657&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79657&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79657&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79657&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79657&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79657&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79657&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79657&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79657&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79657&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79657&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79657&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79657&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79657&r=mysqlcfg