php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71479 Array value turning into reference after passed to any function by reference
Submitted: 2016-01-28 19:28 UTC Modified: 2016-01-30 04:21 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:1 (33.3%)
From: maxrodikov at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 7.0.2 OS: Any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-01-28 19:28 UTC] maxrodikov at gmail dot com
Description:
------------
Bug can be reproduced on almost any 7.* package and almost any OS.
Tested by myself on Ubuntu / FreeBSD / Windows on PHP package without additional modules.

Seems, that when you pass associative array element to any function/method, that require argument to be passed by reference, you get reference at passed array key instead of scalar/array/NULL value.

Didn't found at documentation anything about such conduct.

Test script:
---------------
<?php
// Can be any user or internal function (class method, e.t.c), accepting parameters by reference
function make_nothing(&$param) {}

$arr1 = ['val' => NULL];
$arr2 = ['val' => 5]; // instead "5" there can be any scalar/array/NULL
// Pass array element to function, that doing nothing
make_nothing($arr2['val']);
// ok, now we have reference instead of value
$arr1 = array_merge($arr1, $arr2);
var_dump($arr1, $arr2);

Expected result:
----------------
array(1) {
  ["val"]=>
  int(5)
}
array(1) {
  ["val"]=>
  int(5)
}

Actual result:
--------------
array(1) {
  ["val"]=>
  &int(5)
}
array(1) {
  ["val"]=>
  &int(5)
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-30 04:21 UTC] laruence@php.net
-Status: Open +Status: Wont fix
 [2016-01-30 04:21 UTC] laruence@php.net
this is a side affect by new design, I don't think it's a problem in general.

it will be truns to no-reference in some other points if it is needed.

thanks
 [2016-01-31 14:14 UTC] maxrodikov at gmail dot com
So maybe add this to migration guide?
It can break legacy code (5.*) in some cases and can be source of unpredictable errors.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 09:01:28 2024 UTC