Skip to content
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
6 changes: 3 additions & 3 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -4325,7 +4325,7 @@ PHP_FUNCTION(array_reverse)
}
/* }}} */

/* {{{ proto array|false array_pad(array input, int pad_size, mixed pad_value)
/* {{{ proto array array_pad(array input, int pad_size, mixed pad_value)
Returns a copy of input array padded with pad_value to size pad_size */
PHP_FUNCTION(array_pad)
{
Expand All @@ -4349,8 +4349,8 @@ PHP_FUNCTION(array_pad)
input_size = zend_hash_num_elements(Z_ARRVAL_P(input));
pad_size_abs = ZEND_ABS(pad_size);
if (pad_size_abs < 0 || pad_size_abs - input_size > Z_L(1048576)) {
php_error_docref(NULL, E_WARNING, "You may only pad up to 1048576 elements at a time");
RETURN_FALSE;
zend_throw_error(NULL, "You may only pad up to 1048576 elements at a time");
return;
}

if (input_size >= pad_size_abs) {
Expand Down
17 changes: 11 additions & 6 deletions ext/standard/tests/array/array_pad.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ var_dump(array_pad(array("", -1, 2.0), 5, array()));
var_dump(array_pad(array("", -1, 2.0), 2, array()));
var_dump(array_pad(array("", -1, 2.0), -3, array()));
var_dump(array_pad(array("", -1, 2.0), -4, array()));
var_dump(array_pad(array("", -1, 2.0), 2000000, 0));

echo "Done\n";
try {
var_dump(array_pad(array("", -1, 2.0), 2000000, 0));
} catch (Error $e) {
echo $e->getMessage() . "\n";
}

?>
--EXPECTF--

DONE
--EXPECT--
array(1) {
[0]=>
int(0)
Expand Down Expand Up @@ -80,7 +86,6 @@ array(4) {
[3]=>
float(2)
}
You may only pad up to 1048576 elements at a time

Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d
bool(false)
Done
DONE