Skip to content

Commit 59b3ab9

Browse files
committed
Promote warnings to errors in array_push()
1 parent 5b8e12a commit 59b3ab9

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
@@ -3146,7 +3146,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
31463146
}
31473147
/* }}} */
31483148

3149-
/* {{{ proto int|false array_push(array stack, mixed var [, mixed ...])
3149+
/* {{{ proto int array_push(array stack, mixed var [, mixed ...])
31503150
Pushes elements onto the end of the array */
31513151
PHP_FUNCTION(array_push)
31523152
{
@@ -3168,8 +3168,8 @@ PHP_FUNCTION(array_push)
31683168

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

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)