mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Promote warnings to error in array_flip()
Closes GH-4576.
This commit is contained in:
committed by
Nikita Popov
parent
d882795d78
commit
d5e9ef8f0f
@@ -2606,7 +2606,7 @@ PHP_FUNCTION(compact)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto array|false array_fill(int start_key, int num, mixed val)
|
||||
/* {{{ proto array array_fill(int start_key, int num, mixed val)
|
||||
Create an array containing num elements starting with index start_key each initialized to val */
|
||||
PHP_FUNCTION(array_fill)
|
||||
{
|
||||
@@ -2621,11 +2621,11 @@ PHP_FUNCTION(array_fill)
|
||||
|
||||
if (EXPECTED(num > 0)) {
|
||||
if (sizeof(num) > 4 && UNEXPECTED(EXPECTED(num > 0x7fffffff))) {
|
||||
php_error_docref(NULL, E_WARNING, "Too many elements");
|
||||
RETURN_FALSE;
|
||||
zend_throw_error(NULL, "Too many elements");
|
||||
return;
|
||||
} else if (UNEXPECTED(start_key > ZEND_LONG_MAX - num + 1)) {
|
||||
php_error_docref(NULL, E_WARNING, "Cannot add element to the array as the next element is already occupied");
|
||||
RETURN_FALSE;
|
||||
zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
|
||||
return;
|
||||
} else if (EXPECTED(start_key >= 0) && EXPECTED(start_key < num)) {
|
||||
/* create packed array */
|
||||
Bucket *p;
|
||||
@@ -2670,8 +2670,8 @@ PHP_FUNCTION(array_fill)
|
||||
} else if (EXPECTED(num == 0)) {
|
||||
RETURN_EMPTY_ARRAY();
|
||||
} else {
|
||||
php_error_docref(NULL, E_WARNING, "Number of elements can't be negative");
|
||||
RETURN_FALSE;
|
||||
zend_throw_error(NULL, "Number of elements can't be negative");
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -14,13 +14,18 @@ echo "*** Testing array_fill() : error conditions ***\n";
|
||||
$start_key = 0;
|
||||
$num = -1;
|
||||
$val = 1;
|
||||
var_dump( array_fill($start_key,$num,$val) );
|
||||
|
||||
echo "Done";
|
||||
try {
|
||||
var_dump( array_fill($start_key,$num,$val) );
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
DONE
|
||||
--EXPECTF--
|
||||
*** Testing array_fill() : error conditions ***
|
||||
Number of elements can't be negative
|
||||
|
||||
Warning: array_fill(): Number of elements can't be negative in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
DONE
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
Bug #61058 (array_fill leaks if start index is PHP_INT_MAX)
|
||||
--FILE--
|
||||
<?php
|
||||
array_fill(PHP_INT_MAX, 2, '*');
|
||||
|
||||
try {
|
||||
array_fill(PHP_INT_MAX, 2, '*');
|
||||
} catch (\Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: array_fill(): Cannot add element to the array as the next element is already occupied in %sbug61058.php on line %d
|
||||
--EXPECT--
|
||||
Cannot add element to the array as the next element is already occupied
|
||||
|
||||
Reference in New Issue
Block a user