Skip to content

Commit 62751b0

Browse files
Girgiaskrakjoe
authored andcommitted
Promote warnings to errors in array_walk(_recursive)()
1 parent 81277a1 commit 62751b0

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

ext/standard/array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */
13991399
SEPARATE_ARRAY(zv);
14001400
thash = Z_ARRVAL_P(zv);
14011401
if (GC_IS_RECURSIVE(thash)) {
1402-
php_error_docref(NULL, E_WARNING, "recursion detected");
1402+
zend_throw_error(NULL, "Recursion detected");
14031403
result = FAILURE;
14041404
break;
14051405
}
@@ -1450,7 +1450,7 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */
14501450
target_hash = Z_OBJPROP_P(array);
14511451
pos = zend_hash_iterator_pos(ht_iter, target_hash);
14521452
} else {
1453-
php_error_docref(NULL, E_WARNING, "Iterated value is no longer an array or object");
1453+
zend_type_error("Iterated value is no longer an array or object");
14541454
result = FAILURE;
14551455
break;
14561456
}

ext/standard/tests/array/bug70713.phpt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ class obj
1919
}
2020

2121
$arr = array('string' => new obj);
22-
array_walk_recursive($arr, 'settype');
22+
23+
try {
24+
array_walk_recursive($arr, 'settype');
25+
} catch (\TypeError $e) {
26+
echo $e->getMessage() . "\n";
27+
}
2328

2429
?>
25-
--EXPECTF--
26-
Warning: array_walk_recursive(): Iterated value is no longer an array or object in %s on line %d
30+
--EXPECT--
31+
Iterated value is no longer an array or object

0 commit comments

Comments
 (0)