| Newsgroups |
php.bugs |
| Message-ID |
<[email protected]> |
From: nikic
Operating system:
PHP version: 7.0Git-2015-12-30 (Git)
Package: Scripting Engine problem
Bug Type: Bug
Bug description:yield from ignores yield-by-reference
Description:
------------
When "yield from" was implemented, we did not consider how it interacts
with yield-by-reference. Right now it is simply ignored and "yield from"
yields all values by-value.
Likely this is not the expected or intended behavior. Instead "yield
from" in a by-reference generator should yield array values and values
from by-reference generators by-reference. "yield from" should generate
an error for iterators (and generators) that do not support by-reference
iteration.
Test script:
---------------
<?php
function &gen(array $array) {
yield from $array;
}
$array = [1, 2, 3];
foreach (gen($array) as &$v) {
$v += 1;
}
var_dump($array);
Expected result:
----------------
array(3) {
[0]=>
int(2)
[1]=>
int(3)
[2]=>
int(4)
}
Actual result:
--------------
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
--
Edit bug report at https://bugs.php.net/bug.php?id=71252&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71252&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71252&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71252&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71252&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71252&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71252&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71252&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71252&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71252&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71252&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71252&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71252&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71252&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71252&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71252&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71252&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71252&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71252&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71252&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71252&r=mysqlcfg