Skip to content

Commit 4a904ff

Browse files
committed
Promote warnings to errors in array_push()
1 parent 5b09e60 commit 4a904ff

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

ext/standard/array.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,7 +3147,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
31473147
}
31483148
/* }}} */
31493149

3150-
/* {{{ proto int|false array_push(array stack, mixed var [, mixed ...])
3150+
/* {{{ proto int array_push(array stack, mixed var [, mixed ...])
31513151
Pushes elements onto the end of the array */
31523152
PHP_FUNCTION(array_push)
31533153
{
@@ -3169,8 +3169,8 @@ PHP_FUNCTION(array_push)
31693169

31703170
if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var) == NULL) {
31713171
Z_TRY_DELREF(new_var);
3172-
php_error_docref(NULL, E_WARNING, "Cannot add element to the array as the next element is already occupied");
3173-
RETURN_FALSE;
3172+
zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
3173+
return;
31743174
}
31753175
}
31763176

ext/standard/tests/array/array_push_error2.phpt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ Test array_push() function : error conditions - max int value as key
1515
echo "*** Testing array_push() : error conditions ***\n";
1616

1717
$array = array(PHP_INT_MAX => 'max');
18-
19-
var_dump(array_push($array, 'new'));
18+
try {
19+
var_dump(array_push($array, 'new'));
20+
} catch (\Error $e) {
21+
echo $e->getMessage() . "\n";
22+
}
2023
var_dump($array);
2124

2225
echo "Done";
2326
?>
2427
--EXPECTF--
2528
*** Testing array_push() : error conditions ***
26-
27-
Warning: array_push(): Cannot add element to the array as the next element is already occupied in %s on line %d
28-
bool(false)
29+
Cannot add element to the array as the next element is already occupied
2930
array(1) {
3031
[%d]=>
3132
string(3) "max"

0 commit comments

Comments
 (0)