@@ -291,6 +291,10 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /
291
291
start = 0 ;
292
292
}
293
293
} else if ((size_t )start > ZSTR_LEN (s11 )) {
294
+ /* Convert to Exception ?
295
+ zend_throw_exception(zend_ce_error_exception, "Offset not contained in string", E_ERROR);
296
+ return;
297
+ */
294
298
RETURN_FALSE ;
295
299
}
296
300
@@ -324,15 +328,15 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /
324
328
}
325
329
/* }}} */
326
330
327
- /* {{{ proto int|false strspn(string str, string mask [, int start [, int len]])
331
+ /* {{{ proto int strspn(string str, string mask [, int start [, int len]])
328
332
Finds length of initial segment consisting entirely of characters found in mask. If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars) */
329
333
PHP_FUNCTION (strspn )
330
334
{
331
335
php_spn_common_handler (INTERNAL_FUNCTION_PARAM_PASSTHRU , STR_STRSPN );
332
336
}
333
337
/* }}} */
334
338
335
- /* {{{ proto int|false strcspn(string str, string mask [, int start [, int len]])
339
+ /* {{{ proto int strcspn(string str, string mask [, int start [, int len]])
336
340
Finds length of initial segment consisting entirely of characters not found in mask. If start or/and length is provide works like strcspn(substr($s,$start,$len),$bad_chars) */
337
341
PHP_FUNCTION (strcspn )
338
342
{
@@ -682,6 +686,9 @@ PHP_FUNCTION(nl_langinfo)
682
686
#endif
683
687
break ;
684
688
default :
689
+ /* TODO Convert to ErrorException
690
+ * zend_throw_exception(zend_ce_error_exception, "", E_ERROR);
691
+ */
685
692
php_error_docref (NULL , E_WARNING , "Item '" ZEND_LONG_FMT "' is not valid" , item );
686
693
RETURN_FALSE ;
687
694
}
@@ -718,6 +725,7 @@ PHP_FUNCTION(strcoll)
718
725
* it needs to be incrementing.
719
726
* Returns: FAILURE/SUCCESS whether the input was correct (i.e. no range errors)
720
727
*/
728
+ /* TODO (maybe) convert docref errors into ErrorException? */
721
729
static inline int php_charmask (const unsigned char * input , size_t len , char * mask )
722
730
{
723
731
const unsigned char * end ;
@@ -907,7 +915,7 @@ PHP_FUNCTION(ltrim)
907
915
}
908
916
/* }}} */
909
917
910
- /* {{{ proto string|false wordwrap(string str [, int width [, string break [, bool cut]]])
918
+ /* {{{ proto string wordwrap(string str [, int width [, string break [, bool cut]]])
911
919
Wraps buffer to selected number of characters using string break char */
912
920
PHP_FUNCTION (wordwrap )
913
921
{
@@ -933,13 +941,13 @@ PHP_FUNCTION(wordwrap)
933
941
}
934
942
935
943
if (breakchar_len == 0 ) {
936
- php_error_docref ( NULL , E_WARNING , "Break string cannot be empty" );
937
- RETURN_FALSE ;
944
+ zend_throw_exception ( zend_ce_error_exception , "Break string cannot be empty" , E_ERROR );
945
+ return ;
938
946
}
939
947
940
948
if (linelength == 0 && docut ) {
941
- php_error_docref ( NULL , E_WARNING , "Can't force cut when width is zero" );
942
- RETURN_FALSE ;
949
+ zend_throw_exception ( zend_ce_error_exception , "Can't force cut when width is zero" , E_ERROR );
950
+ return ;
943
951
}
944
952
945
953
/* Special case for a single-character break as it needs no
@@ -1129,7 +1137,7 @@ PHPAPI void php_explode_negative_limit(const zend_string *delim, zend_string *st
1129
1137
}
1130
1138
/* }}} */
1131
1139
1132
- /* {{{ proto array|false explode(string separator, string str [, int limit])
1140
+ /* {{{ proto array explode(string separator, string str [, int limit])
1133
1141
Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned. */
1134
1142
PHP_FUNCTION (explode )
1135
1143
{
@@ -1145,8 +1153,8 @@ PHP_FUNCTION(explode)
1145
1153
ZEND_PARSE_PARAMETERS_END ();
1146
1154
1147
1155
if (ZSTR_LEN (delim ) == 0 ) {
1148
- php_error_docref ( NULL , E_WARNING , "Empty delimiter" );
1149
- RETURN_FALSE ;
1156
+ zend_throw_exception ( zend_ce_error_exception , "Empty delimiter" , E_ERROR );
1157
+ return ;
1150
1158
}
1151
1159
1152
1160
array_init (return_value );
@@ -1619,7 +1627,7 @@ PHPAPI size_t php_dirname(char *path, size_t len)
1619
1627
}
1620
1628
/* }}} */
1621
1629
1622
- /* {{{ proto string|null dirname(string path[, int levels])
1630
+ /* {{{ proto string dirname(string path[, int levels])
1623
1631
Returns the directory name component of the path */
1624
1632
PHP_FUNCTION (dirname )
1625
1633
{
@@ -1644,7 +1652,7 @@ PHP_FUNCTION(dirname)
1644
1652
ZSTR_LEN (ret ) = zend_dirname (ZSTR_VAL (ret ), str_len );
1645
1653
#endif
1646
1654
} else if (levels < 1 ) {
1647
- php_error_docref ( NULL , E_WARNING , "Invalid argument, levels must be >= 1" );
1655
+ zend_throw_exception ( zend_ce_error_exception , "Invalid argument, levels must be >= 1" , E_ERROR );
1648
1656
zend_string_efree (ret );
1649
1657
return ;
1650
1658
} else {
@@ -1813,8 +1821,8 @@ PHP_FUNCTION(stristr)
1813
1821
ZEND_PARSE_PARAMETERS_END ();
1814
1822
1815
1823
if (!ZSTR_LEN (needle )) {
1816
- php_error_docref ( NULL , E_WARNING , "Empty needle" );
1817
- RETURN_FALSE ;
1824
+ zend_throw_exception ( zend_ce_error_exception , "Empty needle" , E_ERROR );
1825
+ return ;
1818
1826
}
1819
1827
1820
1828
haystack_dup = estrndup (ZSTR_VAL (haystack ), ZSTR_LEN (haystack ));
@@ -1854,8 +1862,8 @@ PHP_FUNCTION(strstr)
1854
1862
ZEND_PARSE_PARAMETERS_END ();
1855
1863
1856
1864
if (!ZSTR_LEN (needle )) {
1857
- php_error_docref ( NULL , E_WARNING , "Empty needle" );
1858
- RETURN_FALSE ;
1865
+ zend_throw_exception ( zend_ce_error_exception , "Empty needle" , E_ERROR );
1866
+ return ;
1859
1867
}
1860
1868
1861
1869
found = php_memnstr (ZSTR_VAL (haystack ), ZSTR_VAL (needle ), ZSTR_LEN (needle ), ZSTR_VAL (haystack ) + ZSTR_LEN (haystack ));
@@ -1900,8 +1908,8 @@ PHP_FUNCTION(strpos)
1900
1908
}
1901
1909
1902
1910
if (!ZSTR_LEN (needle )) {
1903
- php_error_docref ( NULL , E_WARNING , "Empty needle" );
1904
- RETURN_FALSE ;
1911
+ zend_throw_exception ( zend_ce_error_exception , "Empty needle" , E_ERROR );
1912
+ return ;
1905
1913
}
1906
1914
1907
1915
found = (char * )php_memnstr (ZSTR_VAL (haystack ) + offset ,
@@ -2194,8 +2202,8 @@ PHP_FUNCTION(chunk_split)
2194
2202
ZEND_PARSE_PARAMETERS_END ();
2195
2203
2196
2204
if (chunklen <= 0 ) {
2197
- php_error_docref ( NULL , E_WARNING , "Chunk length should be greater than zero" );
2198
- RETURN_FALSE ;
2205
+ zend_throw_exception ( zend_ce_error_exception , "Chunk length should be greater than zero" , E_ERROR );
2206
+ return ;
2199
2207
}
2200
2208
2201
2209
if ((size_t )chunklen > ZSTR_LEN (str )) {
@@ -2350,11 +2358,13 @@ PHP_FUNCTION(substr_replace)
2350
2358
(argc == 3 && Z_TYPE_P (from ) == IS_ARRAY ) ||
2351
2359
(argc == 4 && Z_TYPE_P (from ) != Z_TYPE_P (len ))
2352
2360
) {
2361
+ /* TODO can convert to TypeError ? */
2353
2362
php_error_docref (NULL , E_WARNING , "'start' and 'length' should be of same type - numerical or array " );
2354
2363
RETURN_STR_COPY (Z_STR_P (str ));
2355
2364
}
2356
2365
if (argc == 4 && Z_TYPE_P (from ) == IS_ARRAY ) {
2357
2366
if (zend_hash_num_elements (Z_ARRVAL_P (from )) != zend_hash_num_elements (Z_ARRVAL_P (len ))) {
2367
+ /* TODO can convert to Exception ? */
2358
2368
php_error_docref (NULL , E_WARNING , "'start' and 'length' should have the same number of elements" );
2359
2369
RETURN_STR_COPY (Z_STR_P (str ));
2360
2370
}
@@ -2424,6 +2434,7 @@ PHP_FUNCTION(substr_replace)
2424
2434
zend_tmp_string_release (tmp_repl_str );
2425
2435
RETURN_NEW_STR (result );
2426
2436
} else {
2437
+ /* TODO can convert to Exception ? */
2427
2438
php_error_docref (NULL , E_WARNING , "Functionality of 'start' and 'length' as arrays is not implemented" );
2428
2439
RETURN_STR_COPY (Z_STR_P (str ));
2429
2440
}
@@ -3292,7 +3303,7 @@ PHPAPI zend_string *php_str_to_str(const char *haystack, size_t length, const ch
3292
3303
}
3293
3304
/* }}} */
3294
3305
3295
- /* {{{ proto string|false strtr(string str, string from[, string to])
3306
+ /* {{{ proto string strtr(string str, string from[, string to])
3296
3307
Translates characters in str using given translation tables */
3297
3308
PHP_FUNCTION (strtr )
3298
3309
{
@@ -3310,8 +3321,8 @@ PHP_FUNCTION(strtr)
3310
3321
ZEND_PARSE_PARAMETERS_END ();
3311
3322
3312
3323
if (ac == 2 && Z_TYPE_P (from ) != IS_ARRAY ) {
3313
- php_error_docref ( NULL , E_WARNING , "The second argument is not an array" );
3314
- RETURN_FALSE ;
3324
+ zend_type_error ( "The second argument is not an array" );
3325
+ return ;
3315
3326
}
3316
3327
3317
3328
/* shortcut for empty string */
@@ -3359,6 +3370,7 @@ PHP_FUNCTION(strtr)
3359
3370
}
3360
3371
} else {
3361
3372
if (!try_convert_to_string (from )) {
3373
+ zend_type_error ("Cannot convert 'from' into string." );
3362
3374
return ;
3363
3375
}
3364
3376
@@ -5363,7 +5375,7 @@ PHP_FUNCTION(str_repeat)
5363
5375
ZEND_PARSE_PARAMETERS_END ();
5364
5376
5365
5377
if (mult < 0 ) {
5366
- php_error_docref ( NULL , E_WARNING , "Second argument has to be greater than or equal to 0" );
5378
+ zend_throw_exception ( zend_ce_error_exception , "Second argument has to be greater than or equal to 0" , E_ERROR );
5367
5379
return ;
5368
5380
}
5369
5381
@@ -5401,7 +5413,7 @@ PHP_FUNCTION(str_repeat)
5401
5413
}
5402
5414
/* }}} */
5403
5415
5404
- /* {{{ proto array|string|false count_chars(string input [, int mode])
5416
+ /* {{{ proto array|string count_chars(string input [, int mode])
5405
5417
Returns info about what characters are used in input */
5406
5418
PHP_FUNCTION (count_chars )
5407
5419
{
@@ -5421,8 +5433,8 @@ PHP_FUNCTION(count_chars)
5421
5433
ZEND_PARSE_PARAMETERS_END ();
5422
5434
5423
5435
if (mymode < 0 || mymode > 4 ) {
5424
- php_error_docref ( NULL , E_WARNING , "Unknown mode" );
5425
- RETURN_FALSE ;
5436
+ zend_throw_exception ( zend_ce_error_exception , "Unknown mode" , E_ERROR );
5437
+ return ;
5426
5438
}
5427
5439
5428
5440
buf = (const unsigned char * ) ZSTR_VAL (input );
@@ -5610,8 +5622,8 @@ PHP_FUNCTION(substr_count)
5610
5622
ZEND_PARSE_PARAMETERS_END ();
5611
5623
5612
5624
if (needle_len == 0 ) {
5613
- php_error_docref ( NULL , E_WARNING , "Empty substring" );
5614
- RETURN_FALSE ;
5625
+ zend_throw_exception ( zend_ce_error_exception , "Empty substring" , E_ERROR );
5626
+ return ;
5615
5627
}
5616
5628
5617
5629
p = haystack ;
@@ -5632,6 +5644,7 @@ PHP_FUNCTION(substr_count)
5632
5644
length += (haystack_len - offset );
5633
5645
}
5634
5646
if (length < 0 || ((size_t )length > (haystack_len - offset ))) {
5647
+ /* Convert to Exception ? */
5635
5648
php_error_docref (NULL , E_WARNING , "Invalid length value" );
5636
5649
RETURN_FALSE ;
5637
5650
}
@@ -5687,18 +5700,19 @@ PHP_FUNCTION(str_pad)
5687
5700
}
5688
5701
5689
5702
if (pad_str_len == 0 ) {
5690
- php_error_docref ( NULL , E_WARNING , "Padding string cannot be empty" );
5703
+ zend_throw_exception ( zend_ce_error_exception , "Padding string cannot be empty" , E_ERROR );
5691
5704
return ;
5692
5705
}
5693
5706
5694
5707
if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH ) {
5695
- php_error_docref (NULL , E_WARNING , "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH" );
5708
+ zend_throw_exception (zend_ce_error_exception ,
5709
+ "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH" , E_ERROR );
5696
5710
return ;
5697
5711
}
5698
5712
5699
5713
num_pad_chars = pad_length - ZSTR_LEN (input );
5700
5714
if (num_pad_chars >= INT_MAX ) {
5701
- php_error_docref ( NULL , E_WARNING , "Padding length is too long" );
5715
+ zend_throw_exception ( zend_ce_error_exception , "Padding length is too long" , E_ERROR );
5702
5716
return ;
5703
5717
}
5704
5718
@@ -5916,7 +5930,7 @@ PHP_FUNCTION(str_shuffle)
5916
5930
}
5917
5931
/* }}} */
5918
5932
5919
- /* {{{ proto mixed str_word_count(string str, [int format [, string charlist]])
5933
+ /* {{{ proto array|int|null|false str_word_count(string str, [int format [, string charlist]])
5920
5934
Counts the number of words inside a string. If format of 1 is specified,
5921
5935
then the function will return an array containing all the words
5922
5936
found inside the string. If format of 2 is specified, then the function
@@ -5957,6 +5971,10 @@ PHP_FUNCTION(str_word_count)
5957
5971
/* nothing to be done */
5958
5972
break ;
5959
5973
default :
5974
+ /* Not sure how to proceed here
5975
+ zend_throw_exception(zend_ce_error_exception, "Padding string cannot be empty", E_ERROR);
5976
+ return;
5977
+ */
5960
5978
php_error_docref (NULL , E_WARNING , "Invalid format value " ZEND_LONG_FMT , type );
5961
5979
RETURN_FALSE ;
5962
5980
}
@@ -6058,7 +6076,7 @@ PHP_FUNCTION(money_format)
6058
6076
/* }}} */
6059
6077
#endif
6060
6078
6061
- /* {{{ proto array|false str_split(string str [, int split_length])
6079
+ /* {{{ proto array str_split(string str [, int split_length])
6062
6080
Convert a string to an array. If split_length is specified, break the string down into chunks each split_length characters long. */
6063
6081
PHP_FUNCTION (str_split )
6064
6082
{
@@ -6074,8 +6092,8 @@ PHP_FUNCTION(str_split)
6074
6092
ZEND_PARSE_PARAMETERS_END ();
6075
6093
6076
6094
if (split_length <= 0 ) {
6077
- php_error_docref ( NULL , E_WARNING , "The length of each segment must be greater than zero" );
6078
- RETURN_FALSE ;
6095
+ zend_throw_exception ( zend_ce_error_exception , "The length of each segment must be greater than zero" , E_ERROR );
6096
+ return ;
6079
6097
}
6080
6098
6081
6099
@@ -6114,8 +6132,8 @@ PHP_FUNCTION(strpbrk)
6114
6132
ZEND_PARSE_PARAMETERS_END_EX (RETURN_FALSE );
6115
6133
6116
6134
if (!ZSTR_LEN (char_list )) {
6117
- php_error_docref ( NULL , E_WARNING , "The character list cannot be empty" );
6118
- RETURN_FALSE ;
6135
+ zend_throw_exception ( zend_ce_error_exception , "The character list cannot be empty" , E_ERROR );
6136
+ return ;
6119
6137
}
6120
6138
6121
6139
for (haystack_ptr = ZSTR_VAL (haystack ); haystack_ptr < (ZSTR_VAL (haystack ) + ZSTR_LEN (haystack )); ++ haystack_ptr ) {
@@ -6153,8 +6171,8 @@ PHP_FUNCTION(substr_compare)
6153
6171
if (len == 0 ) {
6154
6172
RETURN_LONG (0L );
6155
6173
} else {
6156
- php_error_docref ( NULL , E_WARNING , "The length must be greater than or equal to zero" );
6157
- RETURN_FALSE ;
6174
+ zend_throw_exception ( zend_ce_error_exception , "The length must be greater than or equal to zero" , E_ERROR );
6175
+ return ;
6158
6176
}
6159
6177
}
6160
6178
@@ -6164,6 +6182,7 @@ PHP_FUNCTION(substr_compare)
6164
6182
}
6165
6183
6166
6184
if ((size_t )offset > ZSTR_LEN (s1 )) {
6185
+ /* Candidate to convert to Exception ? */
6167
6186
php_error_docref (NULL , E_WARNING , "The start position cannot exceed initial string length" );
6168
6187
RETURN_FALSE ;
6169
6188
}
0 commit comments