php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72622 array_walk + array_replace_recursive create references from nothing
Submitted: 2016-07-19 15:49 UTC Modified: -
From: srspam+phpnet at icloud dot com Assigned:
Status: Closed Package: Variables related
PHP Version: 7.0.8 OS: Linux
Private report: No CVE-ID: None
 [2016-07-19 15:49 UTC] srspam+phpnet at icloud dot com
Description:
------------
When an array has been passed to array_walk, with a callback that accepts the first value by reference, and the array is then passed as an argument to array_replace_recursive, an apparent reference is created for each element of the array, which then triggers bug #71241.

The test script attached gives the correct output under php 5.6 and 5.5, but gives the wrong result under 7.0.8

Test script:
---------------
<?php

function walk (array $arr) {
	array_walk($arr, function (&$val, $name) {

	});

	return $arr;
}

$arr3 = ['foo' => 'foo'];
$arr4 = walk(['foo' => 'bar']);
$arr5 = array_replace_recursive($arr3, $arr4);
$arr5['foo'] = 'baz';

var_dump($arr3, $arr4, $arr5);


Expected result:
----------------
array(1) {
  'foo' =>
  string(3) "foo"
}
array(1) {
  'foo' =>
  string(3) "bar"
}
array(1) {
  'foo' =>
  string(3) "baz"
}


Actual result:
--------------
array(1) {
  ["foo"]=>
  string(3) "foo"
}
array(1) {
  ["foo"]=>
  &string(3) "baz"
}
array(1) {
  ["foo"]=>
  &string(3) "baz"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-20 08:13 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3c3b8c8365dc9ac7d62034c9eecbabb4800b7353
Log: Fixed bug #72622 (array_walk + array_replace_recursive create references from nothing)
 [2016-07-20 08:13 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:29 UTC] davey@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3c3b8c8365dc9ac7d62034c9eecbabb4800b7353
Log: Fixed bug #72622 (array_walk + array_replace_recursive create references from nothing)
 [2016-10-17 10:10 UTC] bwoebi@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3c3b8c8365dc9ac7d62034c9eecbabb4800b7353
Log: Fixed bug #72622 (array_walk + array_replace_recursive create references from nothing)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC