Bug #77489 [NEW]: Yield inside IF instruction
| From: | hlecorche at e-commit dot fr | Date: | Sat, 19 Jan 2019 10:54:11 +0000 |
| Subject: | Bug #77489 [NEW]: Yield inside IF instruction | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-219087@lists.php.net to get a copy of this message | ||
From: hlecorche at e-commit dot fr
Operating system: Debian GNU/Linux
PHP version: 7.2.14
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Yield inside IF instruction
Description:
------------
When a function has a YIELD instruction inside a IF instruction, the
yield instruction is called even if the IF INSTRUCTION is not true.
Tested whith 7.0.33, 7.1.26 and 7.2.14 versions.
Test script:
---------------
function gen_one_to_three($useYield = true)
{
$result = [];
for ($i = 1; $i <= 3; $i++) {
if (true === $useYield) {
yield $i;
} else {
$result[] = $i;
}
}
if (false === $useYield) {
return $result;
}
}
$return1 = gen_one_to_three(true);
echo get_class($return1)
$return2 = gen_one_to_three(false);
echo get_class($return2);
Expected result:
----------------
Generator
PHP Warning: get_class() expects parameter 1 to be object, array given
Actual result:
--------------
Generator
Generator
--
Edit bug report at https://bugs.php.net/bug.php?id=77489&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77489&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77489&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77489&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77489&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77489&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77489&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77489&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77489&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77489&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77489&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77489&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77489&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77489&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77489&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77489&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77489&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77489&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77489&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77489&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77489&r=mysqlcfg