Skip to content

Commit 7680d5b

Browse files
committed
Promote warnings to errors in array_push()
1 parent 6c0eb1b commit 7680d5b

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

ext/standard/array.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,7 +3151,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H
31513151
}
31523152
/* }}} */
31533153

3154-
/* {{{ proto int|false array_push(array stack, mixed var [, mixed ...])
3154+
/* {{{ proto int array_push(array stack, mixed var [, mixed ...])
31553155
Pushes elements onto the end of the array */
31563156
PHP_FUNCTION(array_push)
31573157
{
@@ -3173,8 +3173,8 @@ PHP_FUNCTION(array_push)
31733173

31743174
if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var) == NULL) {
31753175
Z_TRY_DELREF(new_var);
3176-
php_error_docref(NULL, E_WARNING, "Cannot add element to the array as the next element is already occupied");
3177-
RETURN_FALSE;
3176+
zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
3177+
return;
31783178
}
31793179
}
31803180

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ function stream_wrapper_restore(string $protocol): bool {}
5757

5858
/* array.c */
5959

60-
/** @return int|false */
61-
function array_push(array &$stack, ...$args) {}
60+
function array_push(array &$stack, ...$args): int {}
6261

6362
function krsort(array &$arg, int $sort_flags = SORT_REGULAR): bool {}
6463

ext/standard/basic_functions_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ZEND_END_ARG_INFO()
6565

6666
#define arginfo_stream_wrapper_restore arginfo_stream_wrapper_unregister
6767

68-
ZEND_BEGIN_ARG_INFO_EX(arginfo_array_push, 0, 0, 1)
68+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_push, 0, 1, IS_LONG, 0)
6969
ZEND_ARG_TYPE_INFO(1, stack, IS_ARRAY, 0)
7070
ZEND_ARG_VARIADIC_INFO(0, args)
7171
ZEND_END_ARG_INFO()

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)