@@ -334,7 +334,7 @@ static const mbfl_encoding *php_mb_get_encoding(zend_string *encoding_name) {
334
334
335
335
encoding = mbfl_name2encoding (ZSTR_VAL (encoding_name ));
336
336
if (!encoding ) {
337
- php_error_docref ( NULL , E_WARNING , "Unknown encoding \"%s\"" , ZSTR_VAL (encoding_name ));
337
+ zend_value_error ( "Unknown encoding \"%s\"" , ZSTR_VAL (encoding_name ));
338
338
return NULL ;
339
339
}
340
340
@@ -1400,8 +1400,9 @@ PHP_FUNCTION(mb_language)
1400
1400
} else {
1401
1401
zend_string * ini_name = zend_string_init ("mbstring.language" , sizeof ("mbstring.language" ) - 1 , 0 );
1402
1402
if (FAILURE == zend_alter_ini_entry (ini_name , name , PHP_INI_USER , PHP_INI_STAGE_RUNTIME )) {
1403
- php_error_docref (NULL , E_WARNING , "Unknown language \"%s\"" , ZSTR_VAL (name ));
1404
- RETVAL_FALSE ;
1403
+ zend_value_error ("Unknown language \"%s\"" , ZSTR_VAL (name ));
1404
+ zend_string_release_ex (ini_name , 0 );
1405
+ RETURN_THROWS ();
1405
1406
} else {
1406
1407
RETVAL_TRUE ;
1407
1408
}
@@ -1431,8 +1432,8 @@ PHP_FUNCTION(mb_internal_encoding)
1431
1432
} else {
1432
1433
encoding = mbfl_name2encoding (name );
1433
1434
if (!encoding ) {
1434
- php_error_docref ( NULL , E_WARNING , "Unknown encoding \"%s\"" , name );
1435
- RETURN_FALSE ;
1435
+ zend_value_error ( "Unknown encoding \"%s\"" , name );
1436
+ RETURN_THROWS () ;
1436
1437
} else {
1437
1438
MBSTRG (current_internal_encoding ) = encoding ;
1438
1439
MBSTRG (internal_encoding_set ) = 1 ;
@@ -1556,8 +1557,8 @@ PHP_FUNCTION(mb_http_output)
1556
1557
} else {
1557
1558
encoding = mbfl_name2encoding (name );
1558
1559
if (!encoding ) {
1559
- php_error_docref ( NULL , E_WARNING , "Unknown encoding \"%s\"" , name );
1560
- RETURN_FALSE ;
1560
+ zend_value_error ( "Unknown encoding \"%s\"" , name );
1561
+ RETURN_THROWS () ;
1561
1562
} else {
1562
1563
MBSTRG (http_output_set ) = 1 ;
1563
1564
MBSTRG (current_http_output_encoding ) = encoding ;
@@ -1727,6 +1728,20 @@ PHP_FUNCTION(mb_preferred_mime_name)
1727
1728
}
1728
1729
}
1729
1730
}
1731
+
1732
+ no_encoding = mbfl_name2no_encoding (name );
1733
+ if (no_encoding == mbfl_no_encoding_invalid ) {
1734
+ zend_value_error ("Unknown encoding \"%s\"" , name );
1735
+ RETURN_THROWS ();
1736
+ }
1737
+
1738
+ const char * preferred_name = mbfl_no2preferred_mime_name (no_encoding );
1739
+ if (preferred_name == NULL || * preferred_name == '\0' ) {
1740
+ zend_value_error ("No MIME preferred name corresponding to \"%s\"" , name );
1741
+ RETURN_THROWS ();
1742
+ }
1743
+
1744
+ RETVAL_STRING ((char * )preferred_name );
1730
1745
}
1731
1746
/* }}} */
1732
1747
@@ -1928,8 +1943,8 @@ PHP_FUNCTION(mb_str_split)
1928
1943
ZEND_PARSE_PARAMETERS_END ();
1929
1944
1930
1945
if (split_length <= 0 ) {
1931
- php_error_docref ( NULL , E_WARNING , "The length of each segment must be greater than zero" );
1932
- RETURN_FALSE ;
1946
+ zend_value_error ( "The length of each segment must be greater than zero" );
1947
+ RETURN_THROWS () ;
1933
1948
}
1934
1949
1935
1950
/* fill mbfl_string structure */
@@ -2105,8 +2120,8 @@ PHP_FUNCTION(mb_strpos)
2105
2120
offset += slen ;
2106
2121
}
2107
2122
if (offset < 0 || offset > slen ) {
2108
- php_error_docref ( NULL , E_WARNING , "Offset not contained in string" );
2109
- RETURN_FALSE ;
2123
+ zend_value_error ( "Offset not contained in string" );
2124
+ RETURN_THROWS () ;
2110
2125
}
2111
2126
}
2112
2127
@@ -2118,17 +2133,17 @@ PHP_FUNCTION(mb_strpos)
2118
2133
case 1 :
2119
2134
break ;
2120
2135
case 2 :
2121
- php_error_docref ( NULL , E_WARNING , "Needle has not positive length" );
2122
- break ;
2136
+ zend_value_error ( "Needle has not positive length" );
2137
+ RETURN_THROWS () ;
2123
2138
case 4 :
2124
- php_error_docref ( NULL , E_WARNING , "Unknown encoding or conversion error" );
2125
- break ;
2139
+ zend_value_error ( "Unknown encoding or conversion error" );
2140
+ RETURN_THROWS () ;
2126
2141
case 8 :
2127
- php_error_docref ( NULL , E_NOTICE , "Argument is empty" );
2128
- break ;
2142
+ zend_value_error ( "Argument is empty" );
2143
+ RETURN_THROWS () ;
2129
2144
default :
2130
- php_error_docref ( NULL , E_WARNING , "Unknown error in mb_strpos" );
2131
- break ;
2145
+ zend_value_error ( "Unknown error in mb_strpos" );
2146
+ RETURN_THROWS () ;
2132
2147
}
2133
2148
RETVAL_FALSE ;
2134
2149
}
@@ -2157,8 +2172,8 @@ PHP_FUNCTION(mb_strrpos)
2157
2172
size_t haystack_char_len = mbfl_strlen (& haystack );
2158
2173
if ((offset > 0 && offset > haystack_char_len ) ||
2159
2174
(offset < 0 && - offset > haystack_char_len )) {
2160
- php_error_docref ( NULL , E_WARNING , "Offset is greater than the length of haystack string" );
2161
- RETURN_FALSE ;
2175
+ zend_value_error ( "Offset is greater than the length of haystack string" );
2176
+ RETURN_THROWS () ;
2162
2177
}
2163
2178
}
2164
2179
@@ -2427,8 +2442,8 @@ PHP_FUNCTION(mb_substr_count)
2427
2442
}
2428
2443
2429
2444
if (needle .len == 0 ) {
2430
- php_error_docref ( NULL , E_WARNING , "Empty substring" );
2431
- RETURN_FALSE ;
2445
+ zend_value_error ( "Empty substring" );
2446
+ RETURN_THROWS () ;
2432
2447
}
2433
2448
2434
2449
n = mbfl_substr_count (& haystack , & needle );
@@ -2625,17 +2640,17 @@ PHP_FUNCTION(mb_strimwidth)
2625
2640
}
2626
2641
2627
2642
if (from < 0 || (size_t )from > str_len ) {
2628
- php_error_docref ( NULL , E_WARNING , "Start position is out of range" );
2629
- RETURN_FALSE ;
2643
+ zend_value_error ( "Start position is out of range" );
2644
+ RETURN_THROWS () ;
2630
2645
}
2631
2646
2632
2647
if (width < 0 ) {
2633
2648
width = swidth + width - from ;
2634
2649
}
2635
2650
2636
2651
if (width < 0 ) {
2637
- php_error_docref ( NULL , E_WARNING , "Width is out of range" );
2638
- RETURN_FALSE ;
2652
+ zend_value_error ( "Width is out of range" );
2653
+ RETURN_THROWS () ;
2639
2654
}
2640
2655
2641
2656
if (trimmarker ) {
@@ -2728,7 +2743,7 @@ MBSTRING_API char *php_mb_convert_encoding(const char *input, size_t length, con
2728
2743
if (_to_encoding && strlen (_to_encoding )) {
2729
2744
to_encoding = mbfl_name2encoding (_to_encoding );
2730
2745
if (!to_encoding ) {
2731
- php_error_docref ( NULL , E_WARNING , "Unknown encoding \"%s\"" , _to_encoding );
2746
+ zend_value_error ( "Unknown encoding \"%s\"" , _to_encoding );
2732
2747
return NULL ;
2733
2748
}
2734
2749
} else {
@@ -2821,8 +2836,8 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
2821
2836
if (key ) {
2822
2837
zend_string_release (key );
2823
2838
}
2824
- php_error_docref ( NULL , E_WARNING , "Object is not supported" );
2825
- continue ;
2839
+ zend_value_error ( "Object is not supported" );
2840
+ return NULL ;
2826
2841
}
2827
2842
if (key ) {
2828
2843
zend_hash_add (output , key , & entry_tmp );
@@ -2960,8 +2975,8 @@ PHP_FUNCTION(mb_convert_case)
2960
2975
}
2961
2976
2962
2977
if (case_mode < 0 || case_mode > PHP_UNICODE_CASE_MODE_MAX ) {
2963
- php_error_docref ( NULL , E_WARNING , "Invalid case mode" );
2964
- return ;
2978
+ zend_value_error ( "Invalid case mode" );
2979
+ RETURN_THROWS () ;
2965
2980
}
2966
2981
2967
2982
newstr = mbstring_convert_case (case_mode , str , str_len , & ret_len , enc );
@@ -3088,7 +3103,8 @@ PHP_FUNCTION(mb_detect_encoding)
3088
3103
break ;
3089
3104
}
3090
3105
if (size == 0 ) {
3091
- php_error_docref (NULL , E_WARNING , "Illegal argument" );
3106
+ zend_value_error ("Illegal argument" );
3107
+ RETURN_THROWS ();
3092
3108
}
3093
3109
}
3094
3110
@@ -3156,8 +3172,8 @@ PHP_FUNCTION(mb_encoding_aliases)
3156
3172
3157
3173
encoding = mbfl_name2encoding (name );
3158
3174
if (!encoding ) {
3159
- php_error_docref ( NULL , E_WARNING , "Unknown encoding \"%s\"" , name );
3160
- RETURN_FALSE ;
3175
+ zend_value_error ( "Unknown encoding \"%s\"" , name );
3176
+ RETURN_THROWS () ;
3161
3177
}
3162
3178
3163
3179
array_init (return_value );
@@ -3197,8 +3213,8 @@ PHP_FUNCTION(mb_encode_mimeheader)
3197
3213
if (charset_name != NULL ) {
3198
3214
charset = mbfl_name2encoding (charset_name );
3199
3215
if (!charset ) {
3200
- php_error_docref ( NULL , E_WARNING , "Unknown encoding \"%s\"" , charset_name );
3201
- RETURN_FALSE ;
3216
+ zend_value_error ( "Unknown encoding \"%s\"" , charset_name );
3217
+ RETURN_THROWS () ;
3202
3218
}
3203
3219
} else {
3204
3220
const mbfl_language * lang = mbfl_no2language (MBSTRG (language ));
@@ -3467,8 +3483,8 @@ PHP_FUNCTION(mb_convert_variables)
3467
3483
/* new encoding */
3468
3484
to_encoding = mbfl_name2encoding (to_enc );
3469
3485
if (!to_encoding ) {
3470
- php_error_docref ( NULL , E_WARNING , "Unknown encoding \"%s\"" , to_enc );
3471
- RETURN_FALSE ;
3486
+ zend_value_error ( "Unknown encoding \"%s\"" , to_enc );
3487
+ RETURN_THROWS () ;
3472
3488
}
3473
3489
3474
3490
/* initialize string */
@@ -3603,8 +3619,8 @@ php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type)
3603
3619
if (encoding && encoding_len > 0 ) {
3604
3620
string .encoding = mbfl_name2encoding (encoding );
3605
3621
if (!string .encoding ) {
3606
- php_error_docref ( NULL , E_WARNING , "Unknown encoding \"%s\"" , encoding );
3607
- RETURN_FALSE ;
3622
+ zend_value_error ( "Unknown encoding \"%s\"" , encoding );
3623
+ RETURN_THROWS () ;
3608
3624
}
3609
3625
}
3610
3626
@@ -3912,8 +3928,8 @@ PHP_FUNCTION(mb_send_mail)
3912
3928
str_headers = php_mail_build_headers (Z_ARRVAL_P (headers ));
3913
3929
break ;
3914
3930
default :
3915
- php_error_docref ( NULL , E_WARNING , "headers parameter must be string or array" );
3916
- RETURN_FALSE ;
3931
+ zend_type_error ( "headers parameter must be string or array" );
3932
+ return ;
3917
3933
}
3918
3934
}
3919
3935
if (extra_cmd ) {
@@ -4329,7 +4345,7 @@ MBSTRING_API int php_mb_check_encoding(const char *input, size_t length, const c
4329
4345
if (enc != NULL ) {
4330
4346
encoding = mbfl_name2encoding (enc );
4331
4347
if (!encoding || encoding == & mbfl_encoding_pass ) {
4332
- php_error_docref ( NULL , E_WARNING , "Invalid encoding \"%s\"" , enc );
4348
+ zend_value_error ( "Invalid encoding \"%s\"" , enc );
4333
4349
return 0 ;
4334
4350
}
4335
4351
}
@@ -4363,7 +4379,7 @@ MBSTRING_API int php_mb_check_encoding_recursive(HashTable *vars, const zend_str
4363
4379
if (enc != NULL ) {
4364
4380
encoding = mbfl_name2encoding (ZSTR_VAL (enc ));
4365
4381
if (!encoding || encoding == & mbfl_encoding_pass ) {
4366
- php_error_docref ( NULL , E_WARNING , "Invalid encoding \"%s\"" , ZSTR_VAL (enc ));
4382
+ zend_value_error ( "Invalid encoding \"%s\"" , ZSTR_VAL (enc ));
4367
4383
return 0 ;
4368
4384
}
4369
4385
}
@@ -4467,12 +4483,12 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string
4467
4483
4468
4484
no_enc = enc -> no_encoding ;
4469
4485
if (php_mb_is_unsupported_no_encoding (no_enc )) {
4470
- php_error_docref ( NULL , E_WARNING , "Unsupported encoding \"%s\"" , ZSTR_VAL (enc_name ));
4486
+ zend_value_error ( "Unsupported encoding \"%s\"" , ZSTR_VAL (enc_name ));
4471
4487
return -1 ;
4472
4488
}
4473
4489
4474
4490
if (str_len == 0 ) {
4475
- php_error_docref ( NULL , E_WARNING , "Empty string" );
4491
+ zend_value_error ( "Empty string" );
4476
4492
return -1 ;
4477
4493
}
4478
4494
@@ -4547,7 +4563,7 @@ static inline zend_string *php_mb_chr(zend_long cp, zend_string *enc_name)
4547
4563
4548
4564
no_enc = enc -> no_encoding ;
4549
4565
if (php_mb_is_unsupported_no_encoding (no_enc )) {
4550
- php_error_docref ( NULL , E_WARNING , "Unsupported encoding \"%s\"" , ZSTR_VAL (enc_name ));
4566
+ zend_value_error ( "Unsupported encoding \"%s\"" , ZSTR_VAL (enc_name ));
4551
4567
return NULL ;
4552
4568
}
4553
4569
@@ -4835,15 +4851,17 @@ MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t ol
4835
4851
if (mode ) {
4836
4852
if ((offset > 0 && (size_t )offset > haystack_char_len ) ||
4837
4853
(offset < 0 && (size_t )(- offset ) > haystack_char_len )) {
4838
- php_error_docref (NULL , E_WARNING , "Offset is greater than the length of haystack string" );
4854
+ zend_value_error ("Offset is greater than the length of haystack string" );
4855
+ n = -1 ;
4839
4856
break ;
4840
4857
}
4841
4858
} else {
4842
4859
if (offset < 0 ) {
4843
4860
offset += (zend_long )haystack_char_len ;
4844
4861
}
4845
4862
if (offset < 0 || (size_t )offset > haystack_char_len ) {
4846
- php_error_docref (NULL , E_WARNING , "Offset not contained in string" );
4863
+ zend_value_error ("Offset not contained in string" );
4864
+ n = -1 ;
4847
4865
break ;
4848
4866
}
4849
4867
}
0 commit comments