}
/* }}} */
-/* {{{ proto int|false array_push(array stack, mixed var [, mixed ...])
+/* {{{ proto int array_push(array stack, mixed var [, mixed ...])
Pushes elements onto the end of the array */
PHP_FUNCTION(array_push)
{
if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var) == NULL) {
Z_TRY_DELREF(new_var);
- 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;
}
}
/* array.c */
-/** @return int|false */
-function array_push(array &$stack, ...$args) {}
+function array_push(array &$stack, ...$args): int {}
function krsort(array &$arg, int $sort_flags = SORT_REGULAR): bool {}
#define arginfo_stream_wrapper_restore arginfo_stream_wrapper_unregister
-ZEND_BEGIN_ARG_INFO_EX(arginfo_array_push, 0, 0, 1)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_push, 0, 1, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(1, stack, IS_ARRAY, 0)
ZEND_ARG_VARIADIC_INFO(0, args)
ZEND_END_ARG_INFO()
echo "*** Testing array_push() : error conditions ***\n";
$array = array(PHP_INT_MAX => 'max');
-
-var_dump(array_push($array, 'new'));
+try {
+ var_dump(array_push($array, 'new'));
+} catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
var_dump($array);
echo "Done";
?>
--EXPECTF--
*** Testing array_push() : error conditions ***
-
-Warning: array_push(): Cannot add element to the array as the next element is already occupied in %s on line %d
-bool(false)
+Cannot add element to the array as the next element is already occupied
array(1) {
[%d]=>
string(3) "max"