|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-04-10 13:02 UTC] elliotlevin at hotmail dot com
Description: ------------ When generators were implemented, a generator function could return another generator even if it was a return by reference generator. In PHP7 this now produces a warning because it is not a variable. See http://3v4l.org/sFR11#vphp7@20141101 Test script: --------------- <?php function & genRefInner() { $var = 1; yield $var; } function & genRefOuter() { return genRefInner(); } foreach(genRefOuter() as $i) { var_dump($i); } ?> Expected result: ---------------- int(1) Actual result: -------------- Notice: Only variable references should be returned by reference in /in/sFR11 on line 9 int(1) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 03:00:01 2025 UTC |
Another interesting case I didn't consider before is this: <?php class A { public function &gen() { yield; } } class B extends A { public function gen() { yield; } } ?> Currently this throws the usual LSP strict standards notice, because by-reference returns are covariant. Intuitively this seem correct to me as well, as you can iterate a by-ref generator by-val, but can't iterate a by-val generator by-ref.