xref: /PHP-8.0/ext/standard/tests/array/bug42177.phpt (revision 20edea5a)
1--TEST--
2Bug #42177 (Warning "array_merge_recursive(): recursion detected" comes again...)
3--FILE--
4<?php
5
6$a1 = array( 'key1' => 1, 'key3' => 2 );
7$a2 = array();
8$a1 = array_merge_recursive( $a1, $a2 );
9$a1 = array_merge_recursive( $a1, $a2 );
10unset( $a1, $a2 );
11
12$a1 = array();
13$a2 = array( 'key1' => 1, 'key3' => 2 );
14$a1 = array_merge_recursive( $a1, $a2 );
15$a1 = array_merge_recursive( $a1, $a2 );
16unset( $a1, $a2 );
17
18$a1 = array();
19$a2 = array( 'key1' => &$a1 );
20$a1 = array_merge_recursive( $a1, $a2 );
21try {
22    $a1 = array_merge_recursive( $a1, $a2 );
23} catch (\Error $e) {
24    echo $e->getMessage() . " on line " . $e->getLine() . "\n";
25}
26unset( $a1, $a2 );
27
28$x = 'foo';
29$y =& $x;
30$a1 = array($x, $y, $x, $y);
31$a2 = array( 'key1' => $a1, $x, $y );
32$a1 = array_merge_recursive( $a1, $a2 );
33$a1 = array_merge_recursive( $a1, $a2 );
34unset( $a1, $a2 );
35
36?>
37--EXPECT--
38Recursion detected on line 19
39