]> granicus.if.org Git - php/commitdiff
Use TypeError instead of warning in implode()
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 31 May 2019 09:04:13 +0000 (11:04 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 31 May 2019 09:04:13 +0000 (11:04 +0200)
These are again manual argument type checks.

ext/opcache/Optimizer/zend_func_info.c
ext/standard/string.c
ext/standard/tests/strings/implode1.phpt
ext/standard/tests/strings/join_error.phpt
ext/standard/tests/strings/join_variation2.phpt

index 651920c3cf62f4719a18db955eb139bf6b263cb6..6d881b0f390dfaab44341443c8f079601de6a38c 100644 (file)
@@ -231,8 +231,8 @@ static const func_info_t func_infos[] = {
        F1("strip_tags",                   MAY_BE_STRING),
        F0("similar_text",                 MAY_BE_LONG),
        F1("explode",                      MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
-       FN("implode",                      MAY_BE_NULL | MAY_BE_STRING),
-       FN("join",                         MAY_BE_NULL | MAY_BE_STRING),
+       FN("implode",                      MAY_BE_STRING),
+       FN("join",                         MAY_BE_STRING),
        FN("setlocale",                    MAY_BE_FALSE | MAY_BE_STRING),
        F1("localeconv",                   MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_LONG | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY),
 #if HAVE_NL_LANGINFO
index 39739c82c0af7a42a070e57a9797cc158ccc1cac..860dfd59d7ecf55885dc7cd5bfdaf41c31f698c0 100644 (file)
@@ -1283,7 +1283,7 @@ PHP_FUNCTION(implode)
 
        if (arg2 == NULL) {
                if (Z_TYPE_P(arg1) != IS_ARRAY) {
-                       php_error_docref(NULL, E_WARNING, "Argument must be an array");
+                       zend_type_error("Argument must be an array");
                        return;
                }
 
@@ -1298,7 +1298,7 @@ PHP_FUNCTION(implode)
                        glue = zval_get_tmp_string(arg1, &tmp_glue);
                        pieces = arg2;
                } else {
-                       php_error_docref(NULL, E_WARNING, "Invalid arguments passed");
+                       zend_type_error("Invalid arguments passed");
                        return;
                }
        }
index 3dc022d351a12d2b8e1bf71988fc7ef0179c0ac9..494ebaf6102c7267186820fd75e89e0ed34cce45 100644 (file)
Binary files a/ext/standard/tests/strings/implode1.phpt and b/ext/standard/tests/strings/implode1.phpt differ
index 832fb58c05aa0858d6eb6f0c9a49e581cea2eb3e..fa15b75da58eab8d0e1d508cb6dc78589f42c31f 100644 (file)
@@ -14,15 +14,17 @@ echo "*** Testing join() : error conditions ***\n";
 echo "\n-- Testing join() with less than expected no. of arguments --\n";
 $glue = 'string_val';
 
-var_dump( join($glue));
+try {
+    var_dump(join($glue));
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
 
 echo "Done\n";
 ?>
---EXPECTF--
+--EXPECT--
 *** Testing join() : error conditions ***
 
 -- Testing join() with less than expected no. of arguments --
-
-Warning: join(): Argument must be an array in %s on line %d
-NULL
+Argument must be an array
 Done
index 03b3250b40d9624d5dc8ebe2c9aa5d2d4eac01b3..16e053cce10ac80b02b04d52487896c336da9bb4 100644 (file)
@@ -86,12 +86,16 @@ $values =  array (
 echo "\n--- Testing join() by supplying different values for 'pieces' argument ---\n";
 $counter = 1;
 for($index = 0; $index < count($values); $index ++) {
-  echo "-- Iteration $counter --\n";
-  $pieces = $values [$index];
+    echo "-- Iteration $counter --\n";
+    $pieces = $values [$index];
 
-  var_dump( join($glue, $pieces) );
+    try {
+        var_dump( join($glue, $pieces) );
+    } catch (TypeError $e) {
+        echo $e->getMessage(), "\n";
+    }
 
-  $counter ++;
+    $counter ++;
 }
 
 // close the resources used
@@ -99,100 +103,54 @@ fclose($fp);
 
 echo "Done\n";
 ?>
---EXPECTF--
+--EXPECT--
 *** Testing join() : usage variations ***
 
 --- Testing join() by supplying different values for 'pieces' argument ---
 -- Iteration 1 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 2 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 3 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 4 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 5 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 6 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 7 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 8 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 9 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 10 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 11 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 12 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 13 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 14 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 15 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 16 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 17 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 18 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 19 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 20 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 21 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 22 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 -- Iteration 23 --
-
-Warning: join(): Invalid arguments passed in %s on line %d
-NULL
+Invalid arguments passed
 Done