|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-08-25 08:02 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2017-08-25 08:02 UTC] requinix@php.net
[2017-08-26 01:06 UTC] alditis at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 13 19:00:01 2025 UTC |
Description: ------------ yield-by-reference in the class method not working I how expected. Test script: --------------- class Test { public $data = []; function __construct($data){ $this->data = $data; } function &getIterator($d) { $this->data = $d; foreach ($d as $key => $value) { yield $key => $value; } } function printData() { foreach ($this->data as $key => $value) { echo($key . ':' . $value . PHP_EOL); } } } $data = array('one'=>'Curly', 'two'=>'Larry', 'three'=>'Moe'); $t = new Test($data); foreach ($t->getIterator($data) as $key => &$value) { $value = strtoupper($value); } $t->printData(); Expected result: ---------------- I expected names in uppercase: one:CURLY two:LARRY three:MOE Actual result: -------------- $t->printData() of the test script display: one:Curly two:Larry three:Moe