Bug #79511 [NEW]: Return is silently ignored with yield even if yield is never reached

From: Date: Thu, 23 Apr 2020 00:38:19 +0000
Subject: Bug #79511 [NEW]: Return is silently ignored with yield even if yield is never reached
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226723@lists.php.net to get a copy of this message
From: michael dot vorisek at email dot cz Operating system: any PHP version: 7.4.5 Package: Scripting Engine problem Bug Type: Bug Bug description:Return is silently ignored with yield even if yield is never reached Description: ------------ See test script Test script: --------------- function x(): iterable { yield 'a'; return ['b']; // silently ignored! } function y(): iterable { if (false) { yield 'c'; } return ['d']; // not returned at all - yield above needs to be commented out even if the condition is never matched! } foreach (x() as $v) {echo $v."\n";} echo "\n"; foreach (y() as $v) {echo $v."\n";} Expected result: ---------------- a b d Actual result: -------------- a -- Edit bug report at https://bugs.php.net/bug.php?id=79511&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79511&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79511&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79511&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79511&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79511&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79511&r=support Expected behavior: https://bugs.php.net/fix.php?id=79511&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79511&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79511&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79511&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79511&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79511&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79511&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79511&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79511&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79511&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79511&r=mysqlcfg

« previous php.bugs (#226723) next »