-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible regression with spreading nested arrays into a function call and references #14202
Comments
It does seem like this should work. I think the issue is that Edit: Actually, |
See #14205. This turns out not to be an easy fix. I believe the commit that broke this is d1a3874, although I couldn't verify because the code no longer compiles for me. Going into a bit more detail, your issue can be reduced to the following: function test(&$v) {
$v = 7;
}
$args = [[1]];
test(...$args[0]);
var_dump($args[0]); This dumps function test(&$v) {
$v = 7;
}
$args = [[1]];
$argsCopy = $args;
test(...$args[0]);
var_dump($argsCopy[0]); Here, The issue is complex to explain, let me do it anyway for the sake of documentation. It basically boils down to how
None of those are really what we need. In this particular case, we would need a fetch mode that works the same as read+write, but that doesn't emit any indirect modification or related warnings (see Zend/tests/bug78356.php with this patch). Or better yet, warns only if any of the params are by-ref. Furthermore, always fetching by r+w has the downside of always separating arrays, even if unnecessary when all parameters are by-value. Anyway, all of this to say, I don't think fixing this is worthwhile. /cc @bwoebi |
Thanks for the thorough investigation 👍
That's surprising given that my issue (https://3v4l.org/erN2Q) only occurred >= 7.3. |
@iTob191 Interesting. Unfortunately, 7.2/7.3 also doesn't build for me, and 7.3 changed too many things to look through the commits. There's likely some other factor regarding references for your specific case, but the root issue remains. |
Description
I've noticed the following possible regression:
Starting with PHP 7.3, the output of the above code has changed:
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. 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 Version
PHP 7.3.0 - PHP 8.3.7
Operating System
No response
The text was updated successfully, but these errors were encountered: