Skip to content

Promote warnings to errors in array_walk(_recursive)() #4589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */
SEPARATE_ARRAY(zv);
thash = Z_ARRVAL_P(zv);
if (GC_IS_RECURSIVE(thash)) {
php_error_docref(NULL, E_WARNING, "recursion detected");
zend_throw_error(NULL, "Recursion detected");
result = FAILURE;
break;
}
Expand Down Expand Up @@ -1446,7 +1446,7 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */
target_hash = Z_OBJPROP_P(array);
pos = zend_hash_iterator_pos(ht_iter, target_hash);
} else {
php_error_docref(NULL, E_WARNING, "Iterated value is no longer an array or object");
zend_type_error("Iterated value is no longer an array or object");
result = FAILURE;
break;
}
Expand Down
11 changes: 8 additions & 3 deletions ext/standard/tests/array/bug70713.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ class obj
}

$arr = array('string' => new obj);
array_walk_recursive($arr, 'settype');

try {
array_walk_recursive($arr, 'settype');
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}

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