|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-05-31 18:49 UTC] requinix@php.net
-Status: Open
+Status: Verified
-Package: *General Issues
+Package: Scripting Engine problem
[2020-06-08 09:32 UTC] nikic@php.net
[2020-06-08 09:32 UTC] nikic@php.net
-Status: Verified
+Status: Closed
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 09:00:01 2025 UTC |
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