rfc:generator-return-expressions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:generator-return-expressions [2015/03/09 15:49] – rewording rdlowreyrfc:generator-return-expressions [2015/03/09 16:23] – formatting rdlowrey
Line 2: Line 2:
   * Version: 0.1   * Version: 0.1
   * Date: 2015-02-18   * Date: 2015-02-18
-  * Authors: Daniel Lowrey <rdlowrey@php.net>+  * Author: Daniel Lowrey <rdlowrey@php.net>
   * Contributors: Nikita Popov <nikic@php.net>   * Contributors: Nikita Popov <nikic@php.net>
   * Status: Under Discussion   * Status: Under Discussion
Line 170: Line 170:
     return $bar + 42; // unambiguous execution "result"     return $bar + 42; // unambiguous execution "result"
 }; };
 +?>
 </code> </code>
 +
 +
 +===== Reference Returns =====
 +
 +Generators currently utilize the `&` operator to indicate values will be yielded by-reference:
 +
 +<code php>
 +<?php
 +function &gen_reference() {
 +    $value = 3;
 +
 +    while ($value > 0) {
 +        yield $value;
 +    }
 +}
 +
 +foreach (gen_reference() as &$number) {
 +    echo (--$number).'... ';
 +}
 +?>
 +</code>
 +
 +As ''function&'' is already in place to modify yield values we have no way to differentiate between by-reference yield values and by-reference return values. While it would be possible to use ''function&'' to mark returns as by-reference, this proposal's position is that no correlation exists between the "reference-ness" of yielded values and return values. Instead of introducing new tokens or syntax to allow by-reference returns this proposal //always// uses ''ZVAL_COPY'' on return zvals. In short: by-reference returns are not supported in generator return expressions.
  
  
rfc/generator-return-expressions.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1