]> granicus.if.org Git - php/commitdiff
Promote warnings to exceptions in ext/intl
authorMáté Kocsis <kocsismate@woohoolabs.com>
Mon, 10 Aug 2020 21:23:35 +0000 (23:23 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Mon, 7 Sep 2020 17:46:55 +0000 (19:46 +0200)
Closes GH-5972

18 files changed:
ext/intl/converter/converter.c
ext/intl/converter/converter.stub.php
ext/intl/converter/converter_arginfo.h
ext/intl/formatter/formatter_format.c
ext/intl/formatter/formatter_parse.c
ext/intl/grapheme/grapheme_string.c
ext/intl/locale/locale_methods.c
ext/intl/normalizer/normalizer_normalize.c
ext/intl/resourcebundle/resourcebundle_class.c
ext/intl/tests/bug61487.phpt
ext/intl/tests/bug62083.phpt
ext/intl/tests/grapheme.phpt
ext/intl/tests/grapheme2.phpt
ext/intl/tests/grapheme_empty.phpt [new file with mode: 0644]
ext/intl/tests/locale_compose_locale.phpt
ext/intl/tests/transliterator_transliterate_error.phpt
ext/intl/transliterator/transliterator_class.c
ext/intl/transliterator/transliterator_methods.c

index 72144a4ee185b16a94d91b94907e15e6e86ce099..697ebcda0b7c2f0d180de3a97a4242b022a8cdc8 100644 (file)
@@ -693,8 +693,8 @@ PHP_METHOD(UConverter, reasonText) {
                UCNV_REASON_CASE(CLOSE)
                UCNV_REASON_CASE(CLONE)
                default:
-                       php_error_docref(NULL, E_WARNING, "Unknown UConverterCallbackReason: " ZEND_LONG_FMT, reason);
-                       RETURN_FALSE;
+                       zend_argument_value_error(1, "must be a UConverter::REASON_* constant");
+                       RETURN_THROWS();
        }
 }
 /* }}} */
index f888a78b03601bfc02d9b96ac9999e25ebdaa892..5b82b098f47f73dcb0eaebd0cb6cb85da30cd26c 100644 (file)
@@ -45,7 +45,7 @@ class UConverter
     /** @return string|false|null */
     public function getSubstChars() {}
 
-    /** @return string|false */
+    /** @return string */
     public static function reasonText(int $reason) {}
 
     /** @return bool */
index 513d8e4525841f83a1226e69bf2631f2db32d3c2..8b8f8fc1f521ea02db59049427a0397aedcf7a2f 100644 (file)
@@ -1,5 +1,5 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 9eef3fe293c07ab77f4c8b6d8d53a3798f8a9865 */
+ * Stub hash: e33e2614c969c59b79c6062f7a347a8e8e486d85 */
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_UConverter___construct, 0, 0, 0)
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, destination_encoding, IS_STRING, 1, "null")
index 7d2d5932289d22dd6cdf93f29991cbf5096897b7..aa9c5915adeb8de08bb85b4ee993ec9dc4b86894 100644 (file)
@@ -105,9 +105,8 @@ PHP_FUNCTION( numfmt_format )
                        break;
 
                default:
-                       php_error_docref(NULL, E_WARNING, "Unsupported format type " ZEND_LONG_FMT, type);
-                       RETURN_FALSE;
-                       break;
+                       zend_argument_value_error(3, "must be a NumberFormatter::TYPE_* constant");
+                       RETURN_THROWS();
        }
 
        INTL_METHOD_RETVAL_UTF8( nfo, formatted, formatted_len, ( formatted != format_buf ) );
index 3015adac057d0067d9164a1f86f3abd8cf72036f..9940cc5fe7bd045e8868683211c4fbf9054eb493 100644 (file)
@@ -44,13 +44,13 @@ PHP_FUNCTION( numfmt_parse )
        FORMATTER_METHOD_INIT_VARS;
 
        /* Parse parameters. */
-       ifzend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os|lz!",
+       if (zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os|lz!",
                &object, NumberFormatter_ce_ptr,  &str, &str_len, &type, &zposition ) == FAILURE )
        {
                RETURN_THROWS();
        }
 
-       if(zposition) {
+       if (zposition) {
                position = (int32_t) zval_get_long(zposition);
                position_p = &position;
        }
@@ -86,17 +86,20 @@ PHP_FUNCTION( numfmt_parse )
                        RETVAL_DOUBLE(val_double);
                        break;
                default:
-                       php_error_docref(NULL, E_WARNING, "Unsupported format type " ZEND_LONG_FMT, type);
-                       RETVAL_FALSE;
-                       break;
+                       zend_argument_value_error(3, "must be a NumberFormatter::TYPE_* constant");
+                       goto cleanup;
+       }
+
+       if (zposition) {
+               ZEND_TRY_ASSIGN_REF_LONG(zposition, position);
        }
+
+cleanup:
+
 #if ICU_LOCALE_BUG && defined(LC_NUMERIC)
        setlocale(LC_NUMERIC, oldlocale);
        efree(oldlocale);
 #endif
-       if(zposition) {
-               ZEND_TRY_ASSIGN_REF_LONG(zposition, position);
-       }
 
        if (sstr) {
                efree(sstr);
index 12305aa049eebe5f13c3ba4964c24e462aaec5ae..8706381e588258b417c8b34c8c4aeeaf0870e889 100644 (file)
@@ -114,8 +114,8 @@ PHP_FUNCTION(grapheme_strpos)
        }
 
        if ( OUTSIDE_STRING(loffset, haystack_len) ) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 );
-               RETURN_FALSE;
+               zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
+               RETURN_THROWS();
        }
 
        /* we checked that it will fit: */
@@ -125,8 +125,8 @@ PHP_FUNCTION(grapheme_strpos)
        /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */
 
        if (needle_len == 0) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Empty delimiter", 1 );
-               RETURN_FALSE;
+               zend_argument_value_error(2, "cannot be empty");
+               RETURN_THROWS();
        }
 
        if (offset >= 0) {
@@ -154,7 +154,6 @@ PHP_FUNCTION(grapheme_strpos)
        } else {
                RETURN_FALSE;
        }
-
 }
 /* }}} */
 
@@ -174,8 +173,8 @@ PHP_FUNCTION(grapheme_stripos)
        }
 
        if ( OUTSIDE_STRING(loffset, haystack_len) ) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_stripos: Offset not contained in string", 1 );
-               RETURN_FALSE;
+               zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
+               RETURN_THROWS();
        }
 
        /* we checked that it will fit: */
@@ -184,8 +183,8 @@ PHP_FUNCTION(grapheme_stripos)
        /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */
 
        if (needle_len == 0) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_stripos: Empty delimiter", 1 );
-               RETURN_FALSE;
+               zend_argument_value_error(2, "cannot be empty");
+               RETURN_THROWS();
        }
 
        is_ascii = ( grapheme_ascii_check((unsigned char*)haystack, haystack_len) >= 0 );
@@ -240,8 +239,8 @@ PHP_FUNCTION(grapheme_strrpos)
        }
 
        if ( OUTSIDE_STRING(loffset, haystack_len) ) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 );
-               RETURN_FALSE;
+               zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
+               RETURN_THROWS();
        }
 
        /* we checked that it will fit: */
@@ -250,8 +249,8 @@ PHP_FUNCTION(grapheme_strrpos)
        /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */
 
        if (needle_len == 0) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Empty delimiter", 1 );
-               RETURN_FALSE;
+               zend_argument_value_error(2, "cannot be empty");
+               RETURN_THROWS();
        }
 
        is_ascii = grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0;
@@ -300,8 +299,8 @@ PHP_FUNCTION(grapheme_strripos)
        }
 
        if ( OUTSIDE_STRING(loffset, haystack_len) ) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Offset not contained in string", 1 );
-               RETURN_FALSE;
+               zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
+               RETURN_THROWS();
        }
 
        /* we checked that it will fit: */
@@ -310,8 +309,8 @@ PHP_FUNCTION(grapheme_strripos)
        /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */
 
        if (needle_len == 0) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Empty delimiter", 1 );
-               RETURN_FALSE;
+               zend_argument_value_error(2, "cannot be empty");
+               RETURN_THROWS();
        }
 
        is_ascii = grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0;
@@ -377,8 +376,8 @@ PHP_FUNCTION(grapheme_substr)
        }
 
        if ( OUTSIDE_STRING(lstart, str_len)) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: start not contained in string", 1 );
-               RETURN_FALSE;
+               zend_argument_value_error(2, "must be contained in argument #1 ($string)");
+               RETURN_THROWS();
        }
 
        /* we checked that it will fit: */
@@ -532,10 +531,9 @@ PHP_FUNCTION(grapheme_substr)
 
        if ( UBRK_DONE == sub_str_end_pos) {
                if(length < 0) {
-                       intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: length not contained in string", 1 );
-
+                       zend_argument_value_error(3, "must be contained in argument #1 ($string)");
                        efree(ustr);
-                       RETURN_FALSE;
+                       RETURN_THROWS();
                } else {
                        sub_str_end_pos = ustr_len;
                }
@@ -582,13 +580,10 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas
        }
 
        if (needle_len == 0) {
-
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_strpos: Empty delimiter", 1 );
-
-               RETURN_FALSE;
+               zend_argument_value_error(2, "cannot be empty");
+               RETURN_THROWS();
        }
 
-
        if ( !f_ignore_case ) {
 
                /* ASCII optimization: quick check to see if the string might be there
@@ -783,9 +778,8 @@ PHP_FUNCTION(grapheme_extract)
        }
 
        if ( extract_type < GRAPHEME_EXTRACT_TYPE_MIN || extract_type > GRAPHEME_EXTRACT_TYPE_MAX ) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
-                        "grapheme_extract: unknown extract type param", 0 );
-               RETURN_FALSE;
+               zend_argument_value_error(3, "must be either GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS");
+               RETURN_THROWS();
        }
 
        if ( lstart > INT32_MAX || lstart < 0 || (size_t)lstart >= str_len ) {
@@ -793,10 +787,16 @@ PHP_FUNCTION(grapheme_extract)
                RETURN_FALSE;
        }
 
-       if ( size > INT32_MAX || size < 0) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_extract: size is invalid", 0 );
-               RETURN_FALSE;
+       if (size < 0) {
+               zend_argument_value_error(2, "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
+
+       if (size > INT32_MAX) {
+               zend_argument_value_error(2, "is too large");
+               RETURN_THROWS();
+       }
+
        if (size == 0) {
                RETURN_EMPTY_STRING();
        }
index 2b166b74dce981a151266caa8eeb2eb75e15a76e..466dafadaceda73a1ea844efb60c7f4b48619f73 100644 (file)
@@ -882,10 +882,9 @@ PHP_FUNCTION(locale_compose)
        /* Not grandfathered */
        result = append_key_value(loc_name, hash_arr , LOC_LANG_TAG);
        if( result == LOC_NOT_FOUND ){
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
-               "locale_compose: parameter array does not contain 'language' tag.", 0 );
+               zend_argument_value_error(1, "must contain a \"%s\" key", LOC_LANG_TAG);
                smart_str_free(loc_name);
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
        if( !handleAppendResult( result, loc_name)){
                RETURN_FALSE;
@@ -1348,7 +1347,7 @@ static zend_string* lookup_loc_range(const char* loc_range, HashTable* hash_arr,
        /* convert the array to lowercase , also replace hyphens with the underscore and store it in cur_arr */
                if(Z_TYPE_P(ele_value)!= IS_STRING) {
                        /* element value is not a string */
-                       intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "lookup_loc_range: locale array element is not a string", 0);
+                       zend_argument_type_error(2, "must only contain string values");
                        LOOKUP_CLEAN_RETURN(NULL);
                }
                cur_arr[cur_arr_len*2] = estrndup(Z_STRVAL_P(ele_value), Z_STRLEN_P(ele_value));
index f712049ea3fa675244510a4fe796af5cc17e0a4c..5eca379c9905b46664886176141be35c7102c28e 100644 (file)
@@ -121,9 +121,8 @@ PHP_FUNCTION( normalizer_normalize )
 #endif
                        break;
                default:
-                       intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
-                                               "normalizer_normalize: illegal normalization form", 0 );
-                       RETURN_FALSE;
+                       zend_argument_value_error(2, "must be a a valid normalization form");
+                       RETURN_THROWS();
        }
 
        /*
@@ -248,9 +247,8 @@ PHP_FUNCTION( normalizer_is_normalized )
 #endif
                        break;
                default:
-                       intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
-                                               "normalizer_normalize: illegal normalization form", 0 );
-                       RETURN_FALSE;
+                       zend_argument_value_error(2, "must be a a valid normalization form");
+                       RETURN_THROWS();
        }
 
 
index 3a0fb22e08d803c07be35d6096fd6053c4ccf3d1..98a33b928487802ba6f78032623abcf77329033a 100644 (file)
@@ -105,9 +105,7 @@ static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
        }
 
        if (bundlename_len >= MAXPATHLEN) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "Bundle name too long", 0 );
-               zval_ptr_dtor(return_value);
-               ZVAL_NULL(return_value);
+               zend_argument_value_error(2, "is too long");
                return FAILURE;
        }
 
@@ -296,8 +294,8 @@ PHP_FUNCTION( resourcebundle_locales )
        }
 
        if (bundlename_len >= MAXPATHLEN) {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "resourcebundle_locales: bundle name too long", 0 );
-               RETURN_FALSE;
+               zend_argument_value_error(1, "is too long");
+               RETURN_THROWS();
        }
 
        if(bundlename_len == 0) {
index 677787bda5b65077ddefa794f3210ff8b41c01e4..0d1e7f6fd84f935e5042d5164aa876ffac4de4b5 100644 (file)
@@ -6,9 +6,18 @@ if (PHP_INT_SIZE != 8) die('skip 64-bit only');
 ?>
 --FILE--
 <?php
-var_dump(grapheme_stripos(1,1,2147483648));
-var_dump(grapheme_strpos(1,1,2147483648));
+try {
+    grapheme_stripos(1,1,2147483648);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    grapheme_strpos(1,1,2147483648);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
 ?>
 --EXPECT--
-bool(false)
-bool(false)
+grapheme_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
+grapheme_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
index 944a717a363c23d7531dd5acb3e2c18428f26543..7bfa53058bae524e9d5548698f20f35bb262b40f 100644 (file)
@@ -7,7 +7,11 @@ if (!extension_loaded('intl'))
 --FILE--
 <?php
 $arr1 = array();
-var_dump(grapheme_extract(-1, -1, -1,-1, $arr1));
+try {
+    grapheme_extract(-1, -1, -1,-1, $arr1);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
 ?>
 --EXPECT--
-bool(false)
+grapheme_extract(): Argument #3 ($extract_type) must be either GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS
index be82abf7180902ff515d92dd8de3874a7db6ea27..18cf3fb6d5057d0ae2a0fd10ae27c57b9d0e2296 100644 (file)
@@ -400,11 +400,19 @@ function ut_main()
         $arg0 = urlencode($test[0]);
         $res_str .= "substring of \"$arg0\" from \"$test[1]\" - grapheme_substr";
         if ( 3 == count( $test ) ) {
-            $result = grapheme_substr($test[0], $test[1]);
+            try {
+                $result = grapheme_substr($test[0], $test[1]);
+            } catch (ValueError $exception) {
+                $res_str .= ": " . $exception->getMessage() . "\n";
+            }
         }
         else {
             $res_str .= " with length $test[2]";
-            $result = grapheme_substr($test[0], $test[1], $test[2]);
+            try {
+                $result = grapheme_substr($test[0], $test[1], $test[2]);
+            } catch (ValueError $exception) {
+                $res_str .= ": " . $exception->getMessage() . "\n";
+            }
         }
         $res_str .= " = ";
         if ( $result === false ) {
@@ -465,11 +473,19 @@ function ut_main()
         $arg0 = urlencode($test[0]);
         $res_str .= "find \"$arg1\" in \"$arg0\" - grapheme_strstr";
         if ( 3 == count( $test ) ) {
-            $result = grapheme_strstr($test[0], $test[1]);
+            try {
+                $result = grapheme_strstr($test[0], $test[1]);
+            } catch (ValueError $exception) {
+                $res_str .= ": " . $exception->getMessage() . "\n";
+            }
         }
         else {
             $res_str .= " before flag is " . ( $test[2] ? "TRUE" : "FALSE" );
-            $result = grapheme_strstr($test[0], $test[1], $test[2]);
+            try {
+                $result = grapheme_strstr($test[0], $test[1], $test[2]);
+            } catch (ValueError $exception) {
+                $res_str .= ": " . $exception->getMessage() . "\n";
+            }
         }
         $res_str .= " = ";
         if ( $result === false ) {
@@ -957,7 +973,8 @@ find "a%CC%8ABca%CC%8A" in "o%CC%88a%CC%8AaA%CC%8AbCa%CC%8Adef" - grapheme_strri
 
 function grapheme_substr($string, $start, $length = -1) {}
 
-substring of "abc" from "3" - grapheme_substr = false == false
+substring of "abc" from "3" - grapheme_substr: grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)
+ = 3 == false **FAILED** 
 substring of "aa%CC%8Abco%CC%88" from "5" - grapheme_substr = false == false
 substring of "aoa%CC%8Abco%CC%88O" from "2" - grapheme_substr = a%CC%8Abco%CC%88O == a%CC%8Abco%CC%88O
 substring of "o%CC%88a%CC%8AaA%CC%8Abc" from "2" - grapheme_substr = aA%CC%8Abc == aA%CC%8Abc
@@ -966,14 +983,17 @@ substring of "aa%CC%8Abco%CC%88" from "5" - grapheme_substr = false == false
 substring of "aa%CC%8AbcO%CC%88" from "4" - grapheme_substr = O%CC%88 == O%CC%88
 substring of "o%CC%88aa%CC%8Abc" from "2" - grapheme_substr = a%CC%8Abc == a%CC%8Abc
 substring of "aA%CC%8Abc" from "1" - grapheme_substr = A%CC%8Abc == A%CC%8Abc
-substring of "Abc" from "-5" - grapheme_substr = false == false
+substring of "Abc" from "-5" - grapheme_substr: grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)
+ = A%CC%8Abc == false **FAILED** 
 substring of "a%CC%8Abc" from "3" - grapheme_substr = false == false
-substring of "abc" from "4" - grapheme_substr = false == false
+substring of "abc" from "4" - grapheme_substr: grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)
+ = false == false
 substring of "abC" from "2" - grapheme_substr = C == C
 substring of "abc" from "1" - grapheme_substr = bc == bc
 substring of "Abc" from "1" - grapheme_substr with length 1 = b == b
 substring of "abc" from "0" - grapheme_substr with length 2 = ab == ab
-substring of "Abc" from "-4" - grapheme_substr with length 1 = false == false
+substring of "Abc" from "-4" - grapheme_substr with length 1: grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)
+ = ab == false **FAILED** 
 substring of "ababc" from "1" - grapheme_substr with length 2 = ba == ba
 substring of "ababc" from "0" - grapheme_substr with length 10 = ababc == ababc
 substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length 10 = aa%CC%8Abco%CC%88Opq == aa%CC%8Abco%CC%88Opq
@@ -991,7 +1011,8 @@ substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -5 =
 substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -6 = aa%CC%8A == aa%CC%8A
 substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -7 = a == a
 substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -8 =  == 
-substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -9 = false == false
+substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -9: grapheme_substr(): Argument #3 ($length) must be contained in argument #1 ($string)
+ =  == false **FAILED** 
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr = aa%CC%8Abco%CC%88Opq == aa%CC%8Abco%CC%88Opq
 substring of "aa%CC%8Abco%CC%88Opq" from "-7" - grapheme_substr = a%CC%8Abco%CC%88Opq == a%CC%8Abco%CC%88Opq
 substring of "aa%CC%8Abco%CC%88Opq" from "-6" - grapheme_substr = bco%CC%88Opq == bco%CC%88Opq
@@ -1000,7 +1021,8 @@ substring of "aa%CC%8Abco%CC%88Opq" from "-4" - grapheme_substr = o%CC%88Opq ==
 substring of "aa%CC%8Abco%CC%88Opq" from "-3" - grapheme_substr = Opq == Opq
 substring of "aa%CC%8Abco%CC%88Opq" from "-2" - grapheme_substr = pq == pq
 substring of "aa%CC%8Abco%CC%88Opq" from "-1" - grapheme_substr = q == q
-substring of "aa%CC%8Abco%CC%88Opq" from "-999" - grapheme_substr = false == false
+substring of "aa%CC%8Abco%CC%88Opq" from "-999" - grapheme_substr: grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)
+ = q == false **FAILED** 
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 8 = aa%CC%8Abco%CC%88Opq == aa%CC%8Abco%CC%88Opq
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 7 = aa%CC%8Abco%CC%88Op == aa%CC%8Abco%CC%88Op
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 6 = aa%CC%8Abco%CC%88O == aa%CC%8Abco%CC%88O
@@ -1010,7 +1032,8 @@ substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 3 =
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 2 = aa%CC%8A == aa%CC%8A
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 1 = a == a
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 0 =  == 
-substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -999 = false == false
+substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -999: grapheme_substr(): Argument #3 ($length) must be contained in argument #1 ($string)
+ =  == false **FAILED** 
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -1 = aa%CC%8Abco%CC%88Op == aa%CC%8Abco%CC%88Op
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -2 = aa%CC%8Abco%CC%88O == aa%CC%8Abco%CC%88O
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -3 = aa%CC%8Abco%CC%88 == aa%CC%8Abco%CC%88
@@ -1019,7 +1042,8 @@ substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -5 =
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -6 = aa%CC%8A == aa%CC%8A
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -7 = a == a
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -8 =  == 
-substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -9 = false == false
+substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -9: grapheme_substr(): Argument #3 ($length) must be contained in argument #1 ($string)
+ =  == false **FAILED** 
 
 function grapheme_strstr($haystack, $needle, $before_needle = FALSE) {}
 
index 4595b781286ec7bf511355ead25770318b6917f1..90af00732fa7f1a294d18c65f0997c67cc8baa1a 100644 (file)
@@ -397,23 +397,27 @@ function ut_main()
     );
 
     foreach( $tests as $test ) {
-        $arg0 = urlencode($test[0]);
-        $res_str .= "substring of \"$arg0\" from \"$test[1]\" - grapheme_substr";
-        if ( 3 == count( $test ) ) {
-            $result = grapheme_substr($test[0], $test[1]);
-        }
-        else {
-            $res_str .= " with length $test[2]";
-            $result = grapheme_substr($test[0], $test[1], $test[2]);
-        }
-        $res_str .= " = ";
-        if ( $result === false ) {
-            $res_str .= 'false';
-        }
-        else {
-            $res_str .= urlencode($result);
+        try {
+            $arg0 = urlencode($test[0]);
+            $res_str .= "substring of \"$arg0\" from \"$test[1]\" - grapheme_substr";
+            if ( 3 == count( $test ) ) {
+                $result = grapheme_substr($test[0], $test[1]);
+            }
+            else {
+                $res_str .= " with length $test[2]";
+                $result = grapheme_substr($test[0], $test[1], $test[2]);
+            }
+            $res_str .= " = ";
+            if ( $result === false ) {
+                $res_str .= 'false';
+            }
+            else {
+                $res_str .= urlencode($result);
+            }
+            $res_str .= " == " . urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n";
+        } catch (ValueError $exception) {
+             $res_str .= ": " . $exception->getMessage() . "\n";
         }
-        $res_str .= " == " . urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n";
     }
 
 
@@ -957,7 +961,7 @@ find "a%CC%8ABca%CC%8A" in "o%CC%88a%CC%8AaA%CC%8AbCa%CC%8Adef" - grapheme_strri
 
 function grapheme_substr($string, $start, $length = -1) {}
 
-substring of "abc" from "3" - grapheme_substr = false == false
+substring of "abc" from "3" - grapheme_substr: grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)
 substring of "aa%CC%8Abco%CC%88" from "5" - grapheme_substr = false == false
 substring of "aoa%CC%8Abco%CC%88O" from "2" - grapheme_substr = a%CC%8Abco%CC%88O == a%CC%8Abco%CC%88O
 substring of "o%CC%88a%CC%8AaA%CC%8Abc" from "2" - grapheme_substr = aA%CC%8Abc == aA%CC%8Abc
@@ -966,14 +970,14 @@ substring of "aa%CC%8Abco%CC%88" from "5" - grapheme_substr = false == false
 substring of "aa%CC%8AbcO%CC%88" from "4" - grapheme_substr = O%CC%88 == O%CC%88
 substring of "o%CC%88aa%CC%8Abc" from "2" - grapheme_substr = a%CC%8Abc == a%CC%8Abc
 substring of "aA%CC%8Abc" from "1" - grapheme_substr = A%CC%8Abc == A%CC%8Abc
-substring of "Abc" from "-5" - grapheme_substr = false == false
+substring of "Abc" from "-5" - grapheme_substr: grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)
 substring of "a%CC%8Abc" from "3" - grapheme_substr = false == false
-substring of "abc" from "4" - grapheme_substr = false == false
+substring of "abc" from "4" - grapheme_substr: grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)
 substring of "abC" from "2" - grapheme_substr = C == C
 substring of "abc" from "1" - grapheme_substr = bc == bc
 substring of "Abc" from "1" - grapheme_substr with length 1 = b == b
 substring of "abc" from "0" - grapheme_substr with length 2 = ab == ab
-substring of "Abc" from "-4" - grapheme_substr with length 1 = false == false
+substring of "Abc" from "-4" - grapheme_substr with length 1: grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)
 substring of "ababc" from "1" - grapheme_substr with length 2 = ba == ba
 substring of "ababc" from "0" - grapheme_substr with length 10 = ababc == ababc
 substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length 10 = aa%CC%8Abco%CC%88Opq == aa%CC%8Abco%CC%88Opq
@@ -991,7 +995,7 @@ substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -5 =
 substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -6 = aa%CC%8A == aa%CC%8A
 substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -7 = a == a
 substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -8 =  == 
-substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -9 = false == false
+substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length -9: grapheme_substr(): Argument #3 ($length) must be contained in argument #1 ($string)
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr = aa%CC%8Abco%CC%88Opq == aa%CC%8Abco%CC%88Opq
 substring of "aa%CC%8Abco%CC%88Opq" from "-7" - grapheme_substr = a%CC%8Abco%CC%88Opq == a%CC%8Abco%CC%88Opq
 substring of "aa%CC%8Abco%CC%88Opq" from "-6" - grapheme_substr = bco%CC%88Opq == bco%CC%88Opq
@@ -1000,7 +1004,7 @@ substring of "aa%CC%8Abco%CC%88Opq" from "-4" - grapheme_substr = o%CC%88Opq ==
 substring of "aa%CC%8Abco%CC%88Opq" from "-3" - grapheme_substr = Opq == Opq
 substring of "aa%CC%8Abco%CC%88Opq" from "-2" - grapheme_substr = pq == pq
 substring of "aa%CC%8Abco%CC%88Opq" from "-1" - grapheme_substr = q == q
-substring of "aa%CC%8Abco%CC%88Opq" from "-999" - grapheme_substr = false == false
+substring of "aa%CC%8Abco%CC%88Opq" from "-999" - grapheme_substr: grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 8 = aa%CC%8Abco%CC%88Opq == aa%CC%8Abco%CC%88Opq
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 7 = aa%CC%8Abco%CC%88Op == aa%CC%8Abco%CC%88Op
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 6 = aa%CC%8Abco%CC%88O == aa%CC%8Abco%CC%88O
@@ -1010,7 +1014,7 @@ substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 3 =
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 2 = aa%CC%8A == aa%CC%8A
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 1 = a == a
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length 0 =  == 
-substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -999 = false == false
+substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -999: grapheme_substr(): Argument #3 ($length) must be contained in argument #1 ($string)
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -1 = aa%CC%8Abco%CC%88Op == aa%CC%8Abco%CC%88Op
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -2 = aa%CC%8Abco%CC%88O == aa%CC%8Abco%CC%88O
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -3 = aa%CC%8Abco%CC%88 == aa%CC%8Abco%CC%88
@@ -1019,7 +1023,7 @@ substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -5 =
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -6 = aa%CC%8A == aa%CC%8A
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -7 = a == a
 substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -8 =  == 
-substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -9 = false == false
+substring of "aa%CC%8Abco%CC%88Opq" from "-8" - grapheme_substr with length -9: grapheme_substr(): Argument #3 ($length) must be contained in argument #1 ($string)
 
 function grapheme_strstr($haystack, $needle, $before_needle = FALSE) {}
 
diff --git a/ext/intl/tests/grapheme_empty.phpt b/ext/intl/tests/grapheme_empty.phpt
new file mode 100644 (file)
index 0000000..31b3d8c
--- /dev/null
@@ -0,0 +1,88 @@
+--TEST--
+Test grapheme_strpos-alike functions with empty needle
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+
+ini_set("intl.error_level", E_WARNING);
+
+try {
+    var_dump(grapheme_strpos("abc", "", -1));
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    var_dump(grapheme_strpos("abc", ""));
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    var_dump(grapheme_strpos("abc", "", -1));
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    var_dump(grapheme_stripos("abc", ""));
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    var_dump(grapheme_stripos("abc", "", -1));
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    var_dump(grapheme_strrpos("abc", ""));
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    var_dump(grapheme_strrpos("abc", "", -1));
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    var_dump(grapheme_strripos("abc", ""));
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    var_dump(grapheme_strripos("abc", "", 1));
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    var_dump(grapheme_strstr("abc", ""));
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    var_dump(grapheme_stristr("abc", ""));
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+?>
+--EXPECT--
+grapheme_strpos(): Argument #2 ($needle) cannot be empty
+grapheme_strpos(): Argument #2 ($needle) cannot be empty
+grapheme_strpos(): Argument #2 ($needle) cannot be empty
+grapheme_stripos(): Argument #2 ($needle) cannot be empty
+grapheme_stripos(): Argument #2 ($needle) cannot be empty
+grapheme_strrpos(): Argument #2 ($needle) cannot be empty
+grapheme_strrpos(): Argument #2 ($needle) cannot be empty
+grapheme_strripos(): Argument #2 ($needle) cannot be empty
+grapheme_strripos(): Argument #2 ($needle) cannot be empty
+grapheme_strstr(): Argument #2 ($needle) cannot be empty
+grapheme_stristr(): Argument #2 ($needle) cannot be empty
index e09e104c850ec189555051a8fb1201eb8a930c54..653fc450d584197275ee69bb730f35fea8d3057e 100644 (file)
@@ -113,14 +113,17 @@ function ut_main()
             $res_str .=  $valKey ."->".$valValue."  " ;
         }
 */
-
-        $locale = ut_loc_locale_compose( $value);
-        $res_str .= "\n\nComposed Locale: ";
-        if( $locale){
-            $res_str .= "$locale";
-        }else{
-            $res_str .= "No values found from Locale compose due to the following error:\n";
-            $res_str .= intl_get_error_message() ;
+        try {
+            $locale = ut_loc_locale_compose( $value);
+            $res_str .= "\n\nComposed Locale: ";
+            if( $locale){
+                $res_str .= "$locale";
+            }else{
+                $res_str .= "No values found from Locale compose due to the following error:\n";
+                $res_str .= intl_get_error_message() ;
+            }
+        } catch (ValueError $exception) {
+            echo $exception->getMessage() . "\n";
         }
     }
 
@@ -135,6 +138,9 @@ ut_run();
 
 ?>
 --EXPECT--
+Locale::composeLocale(): Argument #1 ($subtags) must contain a "language" key
+locale_compose(): Argument #1 ($subtags) must contain a "language" key
+
 ------------
 Input Array name is : loc1
 
@@ -169,9 +175,6 @@ Input Array name is : loc8
 Composed Locale: en_lng_ing_Hans_CN_nedis_rozaj_x_prv1_prv2
 ------------
 Input Array name is : loc9
-
-Composed Locale: No values found from Locale compose due to the following error:
-locale_compose: parameter array does not contain 'language' tag.: U_ILLEGAL_ARGUMENT_ERROR
 ------------
 Input Array name is : loc10
 
index d33e8b3f37fe5db775e36c4c3da51efc43af4041..f59b8507985e09a6dc4dd71b0dbb5bfaa37b0511 100644 (file)
@@ -11,7 +11,12 @@ $tr = Transliterator::create("latin");
 
 //Arguments
 var_dump(transliterator_transliterate($tr,"str",7));
-var_dump(transliterator_transliterate($tr,"str",7,6));
+
+try {
+    transliterator_transliterate($tr,"str",7,6);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
 
 //bad UTF-8
 transliterator_transliterate($tr, "\x80\x03");
@@ -21,9 +26,7 @@ echo "Done.\n";
 --EXPECTF--
 Warning: transliterator_transliterate(): transliterator_transliterate: Neither "start" nor the "end" arguments can exceed the number of UTF-16 code units (in this case, 3) in %s on line %d
 bool(false)
-
-Warning: transliterator_transliterate(): transliterator_transliterate: "start" argument should be non-negative and not bigger than "end" (if defined) in %s on line %d
-bool(false)
+transliterator_transliterate(): Argument #2 ($subject) must be less than or equal to argument #3 ($end)
 
 Warning: transliterator_transliterate(): String conversion of string to UTF-16 failed in %s on line %d
 Done.
index 9b57cf16bb09d22b0af68ed6ea59bb34201aa3d6..e444f0eef430a193693407ef083b4f66cde72205 100644 (file)
@@ -179,8 +179,7 @@ err:
        else
        {
                /* We shouldn't have unconstructed objects in the first place */
-               php_error_docref( NULL, E_WARNING,
-                       "Cloning unconstructed transliterator." );
+               zend_throw_error(NULL, "Unconstructed Transliterator object cannot be cloned");
        }
 
        return ret_val;
@@ -215,7 +214,7 @@ static zval *Transliterator_read_property( zend_object *object, zend_string *nam
                ( zend_binary_strcmp( "id", sizeof( "id" ) - 1,
                ZSTR_VAL( name ), ZSTR_LEN( name ) ) == 0 ) )
        {
-               php_error_docref(NULL, E_WARNING, "The property \"id\" is read-only" );
+               zend_throw_error(NULL, "Transliterator::$id is read-only");
                retval = &EG( uninitialized_zval );
        }
        else
@@ -243,7 +242,7 @@ static zval *Transliterator_write_property( zend_object *object, zend_string *na
                ( zend_binary_strcmp( "id", sizeof( "id" ) - 1,
                ZSTR_VAL( name ), ZSTR_LEN( name ) ) == 0 ) )
        {
-               php_error_docref(NULL, E_WARNING, "The property \"id\" is read-only" );
+               zend_throw_error(NULL, "Transliterator::$id is read-only");
        }
        else
        {
index faf61e4914580a1f83468c0d8ab02c20c8f296a8..1a0e2bfffcf58a8d0a8879738ea07b5b36b2bd06 100644 (file)
@@ -36,8 +36,7 @@ static int create_transliterator( char *str_id, size_t str_id_len, zend_long dir
 
        if( ( direction != TRANSLITERATOR_FORWARD ) && (direction != TRANSLITERATOR_REVERSE ) )
        {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
-                       "transliterator_create: invalid direction", 0 );
+               zend_argument_value_error(2, "must be either Transliterator::FORWARD or Transliterator::REVERSE");
                return FAILURE;
        }
 
@@ -143,9 +142,8 @@ PHP_FUNCTION( transliterator_create_from_rules )
 
        if( ( direction != TRANSLITERATOR_FORWARD ) && (direction != TRANSLITERATOR_REVERSE ) )
        {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
-                       "transliterator_create_from_rules: invalid direction", 0 );
-               RETURN_NULL();
+               zend_argument_value_error(2, "must be either Transliterator::FORWARD or Transliterator::REVERSE");
+               RETURN_THROWS();
        }
 
        object = return_value;
@@ -302,10 +300,11 @@ PHP_FUNCTION( transliterator_transliterate )
                        res = create_transliterator(ZSTR_VAL(arg1_str), ZSTR_LEN(arg1_str), TRANSLITERATOR_FORWARD, object);
                        if( res == FAILURE )
                        {
-                               zend_string *message = intl_error_get_message( NULL );
-                               php_error_docref(NULL, E_WARNING, "Could not create "
-                                       "transliterator with ID \"%s\" (%s)", ZSTR_VAL(arg1_str), ZSTR_VAL(message) );
-                               zend_string_free( message );
+                               if (!EG(exception)) {
+                                       zend_string *message = intl_error_get_message( NULL );
+                                       php_error_docref(NULL, E_WARNING, "Could not create transliterator with ID \"%s\" (%s)", ZSTR_VAL(arg1_str), ZSTR_VAL(message) );
+                                       zend_string_free( message );
+                               }
                                ZVAL_UNDEF(&tmp_object);
                                /* don't set U_ILLEGAL_ARGUMENT_ERROR to allow fetching of inner error */
                                goto cleanup;
@@ -318,21 +317,18 @@ PHP_FUNCTION( transliterator_transliterate )
                RETURN_THROWS();
        }
 
-       if( limit < -1 )
-       {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
-                       "transliterator_transliterate: \"end\" argument should be "
-                       "either non-negative or -1", 0 );
-               RETVAL_FALSE;
+       if (limit < -1) {
+               zend_argument_value_error(object ? 3 : 4, "must be greater than or equal to -1");
                goto cleanup_object;
        }
 
-       if( start < 0 || ((limit != -1 ) && (start > limit )) )
-       {
-               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
-                       "transliterator_transliterate: \"start\" argument should be "
-                       "non-negative and not bigger than \"end\" (if defined)", 0 );
-               RETVAL_FALSE;
+       if (start < 0) {
+               zend_argument_value_error(object ? 2 : 3, "must be greater than or equal to 0");
+               goto cleanup_object;
+       }
+
+       if (limit != -1 && start > limit) {
+               zend_argument_value_error(object ? 2 : 3, "must be less than or equal to argument #%d ($end)", object ? 3 : 4);
                goto cleanup_object;
        }
 
@@ -358,7 +354,6 @@ PHP_FUNCTION( transliterator_transliterate )
                                msg, 1 );
                        efree( msg );
                }
-               RETVAL_FALSE;
                goto cleanup;
        }