[php-src] Issue #11665: Dereferencing an array in foreach unwraps the reference

From: Date: Mon, 10 Jul 2023 16:41:18 +0000
Subject: [php-src] Issue #11665: Dereferencing an array in foreach unwraps the reference
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244937@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11665 Author: bwoebi ### Description The following code (https://3v4l.org/8QBeN): ```php <?php $a = [1]; foreach ((isset($a["key"]) ? [&$a["key"]] : [&$a])[0] as &$v) { var_dump($a); $v++; } var_dump($a); ``` Resulted in this output: ``` array(1) { [0]=> int(1) } array(1) { [0]=> int(1) } ``` But I expected this output instead: ``` array(1) { [0]=> &int(1) } array(1) { [0]=> &int(2) } ``` In PHP 7.2 and before, the output was as expected. Today it's required to use an explicit variable to preserve the reference. ### PHP Version PHP 7.3.0 - master ### Operating System _No response_

« previous php.bugs (#244937) next »