rfc:foreach_unwrap_ref

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
rfc:foreach_unwrap_ref [2021/08/26 13:44] nikicrfc:foreach_unwrap_ref [2021/11/14 17:10] (current) nikic
Line 2: Line 2:
   * Date: 2021-08-13   * Date: 2021-08-13
   * Author: Nikita Popov <nikic@php.net>   * Author: Nikita Popov <nikic@php.net>
-  * Status: Under Discussion+  * Status: Withdrawn
   * Target Version: PHP 8.2   * Target Version: PHP 8.2
   * Implementation: https://github.com/php/php-src/pull/7364   * Implementation: https://github.com/php/php-src/pull/7364
Line 98: Line 98:
  
 Use of complex variables as foreach targets is very unusual, so it is rather unlikely that someone will encounter issues with the reused loop variables in this context. Always performing the unwrap would certainly be possible, but the cure seems worse than disease in this instance. Use of complex variables as foreach targets is very unusual, so it is rather unlikely that someone will encounter issues with the reused loop variables in this context. Always performing the unwrap would certainly be possible, but the cure seems worse than disease in this instance.
 +
 +When foreach is used in conjunction with destructuring, unwrapping will be performed on simple destructuring targets:
 +
 +<PHP>
 +foreach ($array as [&$var, &$complex->var]) {}
 +</PHP>
 +
 +In this example, ''$var'' will be unwrapped because it is a simple variable, while ''$complex->var'' is not affected. As with the non-destructuring case, use of complex variables in this context is unusual and may have side-effects.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
rfc/foreach_unwrap_ref.1629985453.txt.gz · Last modified: 2021/08/26 13:44 by nikic