[php-src] Issue #14202: Possible regression with spreading nested arrays into a function call and references

From: Date: Sat, 11 May 2024 11:49:44 +0000
Subject: [php-src] Issue #14202: Possible regression with spreading nested arrays into a function call and references
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246897@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/14202 Author: iTob191 ### Description I've noticed the following possible regression: ```php $args = [1]; $ref = [&$args]; function test(&$v) { $v = 7; }; test(...$ref[0]); var_dump($args[0]); ``` Starting with PHP 7.3, the output of the above code has changed: ``` $ docker run --rm php:7.2.34 -r "$args = [1]; $ref = [&$args]; function test(&$v) { $v = 7; }; test(...$ref[0]); var_dump($args[0]);" int(7) $ docker run --rm php:7.3 -r "$args = [1]; $ref = [&$args]; function test(&$v) { $v = 7; }; test(...$ref[0]); var_dump($args[0]);" int(1) $ docker run --rm php:8.3.7 -r "$args = [1]; $ref = [&$args]; function test(&$v) { $v = 7; }; test(...$ref[0]); var_dump($args[0]);" int(1) ``` The only entry I've found within PHP 7.3's release notes that might be related is [References returned by Array and Property Accesses are immediately unwrapped](https://www.php.net/manual/en/migration73.incompatible.php#migration73.incompatible.core.reference-unwrapping). But I'm not sure whether this does actually describe the behavior change in the code snippet above. I'm also not really sure whether the code is valid or not. In case it is not, it might be helpful to display a message. There exists a workaround to get the old result by introducing another variable: ```php $temp = &$ref[0]; test(...$temp); ``` ### PHP Version PHP 7.3.0 - PHP 8.3.7 ### Operating System _No response_

« previous php.bugs (#246897) next »