From 0ba34824f5328e96af29113970e0aa22cec95ca1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 31 May 2019 11:04:13 +0200 Subject: [PATCH] Use TypeError instead of warning in implode() These are again manual argument type checks. --- ext/opcache/Optimizer/zend_func_info.c | 4 +- ext/standard/string.c | 4 +- ext/standard/tests/strings/implode1.phpt | Bin 5584 -> 5818 bytes ext/standard/tests/strings/join_error.phpt | 12 +- .../tests/strings/join_variation2.phpt | 106 ++++++------------ 5 files changed, 43 insertions(+), 83 deletions(-) diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index 651920c3cf..6d881b0f39 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -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 diff --git a/ext/standard/string.c b/ext/standard/string.c index 39739c82c0..860dfd59d7 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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; } } diff --git a/ext/standard/tests/strings/implode1.phpt b/ext/standard/tests/strings/implode1.phpt index 3dc022d351a12d2b8e1bf71988fc7ef0179c0ac9..494ebaf6102c7267186820fd75e89e0ed34cce45 100644 GIT binary patch delta 723 zcmcbhy-Rn4Co4xuQKdpPmx99N1SSzDB_&M-O>3@Nh2+GN~iXEeE|n2Sqa zOCd9_L?N+Qp&&CgIki|pOP>qb^^@0fvQMtz}9v z(BwCqqLdgoiAw_2JS{H42nrmC5(c2SLl0;lPyhjAJTWObh2nVKT*$@EK6#>`jmNTwMBE3YmE&3W>!E1(~VI zsl^If`jZ#32~Xzc5)cJR`i1)VV9IuK2}*-xp?ZM2A?k{X5-VXQ9AIbVPXq~QfaEkm zPM93WEdg?YilLE?f)YeC!W}THK(2!s!p|ePIfjRe-GwVWu_!MyFWpKZGq)foKP6Q| z(@MdyD7`c{73loj(&7?@q*R5(JO!|oKtCy{7AxfEDdc44r7EbVaDfb;e2`ya^K{`C zjEshp8%33XgetMessage(), "\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 diff --git a/ext/standard/tests/strings/join_variation2.phpt b/ext/standard/tests/strings/join_variation2.phpt index 03b3250b40..16e053cce1 100644 --- a/ext/standard/tests/strings/join_variation2.phpt +++ b/ext/standard/tests/strings/join_variation2.phpt @@ -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 -- 2.50.1