]> granicus.if.org Git - php/commitdiff
Promote warnings to errors in array_push()
authorGeorge Peter Banyard <girgias@php.net>
Wed, 21 Aug 2019 00:27:27 +0000 (02:27 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 2 Oct 2019 08:38:23 +0000 (10:38 +0200)
This is in line with the engine change from
https://wiki.php.net/rfc/engine_warnings.

ext/standard/array.c
ext/standard/basic_functions.stub.php
ext/standard/basic_functions_arginfo.h
ext/standard/tests/array/array_push_error2.phpt

index c0ea7e1729329b941dbc0ca65f2c5f2e25e6b624..96f9eb4893b86bb0665b850ed040ee714c408879 100644 (file)
@@ -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;
                }
        }
 
index 0922d39115674d74182d8880f1d16734256566bb..4b4bba3ea44b7d23c9fc21a21689fa0a6c86f85e 100755 (executable)
@@ -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 {}
 
index 5a45b55b034436939930d85bff08830c7aa5da9e..49a98fefe45a248510d14f9dcf939cfd3417f885 100755 (executable)
@@ -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()
index 3ab60136bea829efcb3ff99d8ff2f3aa652dff2a..2d19dbc2465fa870da2ead8e2b43abc1384cff57 100644 (file)
@@ -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"