From 1ca4ab09a584b5e3c7caf4466fbb435991c7000b Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 21 Aug 2019 02:27:27 +0200 Subject: [PATCH] Promote warnings to errors in array_push() This is in line with the engine change from https://wiki.php.net/rfc/engine_warnings. --- ext/standard/array.c | 6 +++--- ext/standard/basic_functions.stub.php | 3 +-- ext/standard/basic_functions_arginfo.h | 2 +- ext/standard/tests/array/array_push_error2.phpt | 11 ++++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ext/standard/array.c b/ext/standard/array.c index c0ea7e1729..96f9eb4893 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -3152,7 +3152,7 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H } /* }}} */ -/* {{{ 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) { @@ -3174,8 +3174,8 @@ 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; } } diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 0922d39115..4b4bba3ea4 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -57,8 +57,7 @@ function stream_wrapper_restore(string $protocol): bool {} /* 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 {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 5a45b55b03..49a98fefe4 100755 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -65,7 +65,7 @@ ZEND_END_ARG_INFO() #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() diff --git a/ext/standard/tests/array/array_push_error2.phpt b/ext/standard/tests/array/array_push_error2.phpt index 3ab60136be..2d19dbc246 100644 --- a/ext/standard/tests/array/array_push_error2.phpt +++ b/ext/standard/tests/array/array_push_error2.phpt @@ -15,17 +15,18 @@ Test array_push() function : error conditions - max int value as key 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" -- 2.40.0