Skip to content

Commit 81277a1

Browse files
Girgiaskrakjoe
authored andcommitted
Promote warnings to errors in compact()
1 parent 20edea5 commit 81277a1

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

ext/standard/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu
25562556
} else if (Z_TYPE_P(entry) == IS_ARRAY) {
25572557
if (Z_REFCOUNTED_P(entry)) {
25582558
if (Z_IS_RECURSIVE_P(entry)) {
2559-
php_error_docref(NULL, E_WARNING, "recursion detected");
2559+
zend_throw_error(NULL, "Recursion detected");
25602560
return;
25612561
}
25622562
Z_PROTECT_RECURSION_P(entry);

ext/standard/tests/array/compact_variation1.phpt

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Test compact() function : usage variations - arrays containing references.
1010
/*
1111
* compact variations - arrays with references
1212
*/
13-
echo "*** Testing compact() : usage variations - arrays containg references ***\n";
13+
echo "*** Testing compact() : usage variations - arrays containing references ***\n";
1414
$a = 1;
1515
$b = 2;
1616
$c = 3;
@@ -20,31 +20,34 @@ $arr2 = array("a", array(array(array("b"))));
2020
$arr2[1][0][0][] = &$arr2;
2121
$arr2[1][0][0][] = &$arr2[1];
2222
$arr3 = array(&$string);
23-
var_dump(compact($arr1));
24-
var_dump(compact($arr2));
25-
var_dump(compact($arr3));
26-
echo "Done";
27-
?>
28-
--EXPECTF--
29-
*** Testing compact() : usage variations - arrays containg references ***
3023

31-
Warning: compact(): recursion detected in %s on line %d
32-
array(1) {
33-
["a"]=>
34-
int(1)
24+
try {
25+
var_dump(compact($arr1));
26+
} catch (\Error $e) {
27+
echo $e->getMessage() . "\n";
3528
}
3629

37-
Warning: compact(): recursion detected in %s on line %d
30+
try {
31+
var_dump(compact($arr2));
32+
} catch (\Error $e) {
33+
echo $e->getMessage() . "\n";
34+
}
3835

39-
Warning: compact(): recursion detected in %s on line %d
40-
array(2) {
41-
["a"]=>
42-
int(1)
43-
["b"]=>
44-
int(2)
36+
try {
37+
var_dump(compact($arr3));
38+
} catch (\Error $e) {
39+
echo $e->getMessage() . "\n";
4540
}
41+
?>
42+
43+
DONE
44+
--EXPECT--
45+
*** Testing compact() : usage variations - arrays containing references ***
46+
Recursion detected
47+
Recursion detected
4648
array(1) {
4749
["c"]=>
4850
int(3)
4951
}
50-
Done
52+
53+
DONE

0 commit comments

Comments
 (0)