php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42177 Warning "array_merge_recursive(): recursion detected" comes again...
Submitted: 2007-08-02 12:24 UTC Modified: 2008-03-12 19:22 UTC
Votes:5
Avg. Score:4.6 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:2 (50.0%)
From: rl at ez dot no Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.4.7 OS: linux mandriva 2006
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rl at ez dot no
New email:
PHP Version: OS:

 

 [2007-08-02 12:24 UTC] rl at ez dot no
Description:
------------
Just run the code below and please answer the question:
Why those marked as 'warning' generate warning "array_merge_recursive(): recursion detected" while others marked as 'clear' do not?

<?

// clear
echo "<br>example 1";
$a1 = array( 'a' => 1, 'b' => 2 );
$az = array_merge_recursive( $a1, $a1 );
unset( $a1, $a2 );

// clear
echo "<br>example 2";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = $a1;
$az = array_merge_recursive( $a1, $a2 );
unset( $a1, $a2 );

// clear
echo "<br>example 3";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = & $a1;
$az = array_merge_recursive( $a1, $a2 );
unset( $a1, $a2 );

// warning
echo "<br>example 4";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = & $a1;
$a3 = $a1;
$az = array_merge_recursive( $a1, $a2 );
unset( $a1, $a2 );

// warning
echo "<br>example 5";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = & $a1;
$a3 = $a2;
$az = array_merge_recursive( $a1, $a2 );
unset( $a1, $a2 );

// warning
echo "<br>example 6";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = $a1;
$a2[] = 3; // $a2['c'] = 3; - no matter, warning anyway
$az = array_merge_recursive( $a1, $a2 );
unset( $a1, $a2 );

// clear
echo "<br>example 7";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = & $a1;
$a2[] = 3;
$az = array_merge_recursive( $a1, $a2 );
unset( $a1, $a2 );

// warning
echo "<br>example 8";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = & $a1;
$a3 = $a2;
$az = array_merge_recursive( $a1, $a3 );
unset( $a1, $a2, $a3 );

// warning
echo "<br>example 9";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = $a1;
$a3 = & $a2;
$az = array_merge_recursive( $a1, $a3 );
unset( $a1, $a2, $a3 );

// clear
echo "<br>example 10";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = & $a1;
$a3 = & $a2;
$az = array_merge_recursive( $a1, $a3 );
unset( $a1, $a2, $a3 );

// warning
echo "<br>example 11";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = $a1;
$a3 = $a2;
$a3[] = 3;
$az = array_merge_recursive( $a1, $a3 );
unset( $a1, $a2, $a3 );

// clear
echo "<br>example 12";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = & $a1;
$a3 = & $a2;
$a3[] = 3;
$az = array_merge_recursive( $a1, $a3 );
unset( $a1, $a2, $a3 );

?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-02 14:33 UTC] rl at ez dot no
let's continue

// clear
echo "<br>example 13";
$a1 = array( 'key1' => 1, 'key3' => 2 );
$a2 = array();
$a1 = array_merge_recursive( $a1, $a2 );
$a1 = array_merge_recursive( $a1, $a2 );
unset( $a1, $a2 );

// warning
echo "<br>example 14";
$a1 = array();
$a2 = array( 'key1' => 1, 'key3' => 2 );
$a1 = array_merge_recursive( $a1, $a2 );
$a1 = array_merge_recursive( $a1, $a2 );
unset( $a1, $a2 );

why does example 14 generate a warning while example 13 does not?
seems like if first parameter is empty then function array_merge_recursive just assigns first parameter variable to the second one and makes some internal marks about two arrays which point on the same data but actually are different for a enduser. but second call of array_merge_recursive does not know anything about it.
or something like that... no matter, but these warnings are definitely incorrect.
 [2008-03-12 19:22 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC