@@ -295,6 +295,10 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /
295
295
start = 0 ;
296
296
}
297
297
} else if ((size_t )start > ZSTR_LEN (s11 )) {
298
+ /* Convert to Exception ?
299
+ zend_throw_exception(zend_ce_error_exception, "Offset not contained in string", E_ERROR);
300
+ return;
301
+ */
298
302
RETURN_FALSE ;
299
303
}
300
304
@@ -328,15 +332,15 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /
328
332
}
329
333
/* }}} */
330
334
331
- /* {{{ proto int|false strspn(string str, string mask [, int start [, int len]])
335
+ /* {{{ proto int strspn(string str, string mask [, int start [, int len]])
332
336
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) */
333
337
PHP_FUNCTION (strspn )
334
338
{
335
339
php_spn_common_handler (INTERNAL_FUNCTION_PARAM_PASSTHRU , STR_STRSPN );
336
340
}
337
341
/* }}} */
338
342
339
- /* {{{ proto int|false strcspn(string str, string mask [, int start [, int len]])
343
+ /* {{{ proto int strcspn(string str, string mask [, int start [, int len]])
340
344
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) */
341
345
PHP_FUNCTION (strcspn )
342
346
{
@@ -686,6 +690,9 @@ PHP_FUNCTION(nl_langinfo)
686
690
#endif
687
691
break ;
688
692
default :
693
+ /* TODO Convert to ErrorException
694
+ * zend_throw_exception(zend_ce_error_exception, "", E_ERROR);
695
+ */
689
696
php_error_docref (NULL , E_WARNING , "Item '" ZEND_LONG_FMT "' is not valid" , item );
690
697
RETURN_FALSE ;
691
698
}
@@ -722,6 +729,7 @@ PHP_FUNCTION(strcoll)
722
729
* it needs to be incrementing.
723
730
* Returns: FAILURE/SUCCESS whether the input was correct (i.e. no range errors)
724
731
*/
732
+ /* TODO (maybe) convert docref errors into ErrorException? */
725
733
static inline int php_charmask (const unsigned char * input , size_t len , char * mask )
726
734
{
727
735
const unsigned char * end ;
@@ -911,7 +919,7 @@ PHP_FUNCTION(ltrim)
911
919
}
912
920
/* }}} */
913
921
914
- /* {{{ proto string|false wordwrap(string str [, int width [, string break [, bool cut]]])
922
+ /* {{{ proto string wordwrap(string str [, int width [, string break [, bool cut]]])
915
923
Wraps buffer to selected number of characters using string break char */
916
924
PHP_FUNCTION (wordwrap )
917
925
{
@@ -937,13 +945,13 @@ PHP_FUNCTION(wordwrap)
937
945
}
938
946
939
947
if (breakchar_len == 0 ) {
940
- php_error_docref ( NULL , E_WARNING , "Break string cannot be empty" );
941
- RETURN_FALSE ;
948
+ zend_throw_exception ( zend_ce_error_exception , "Break string cannot be empty" , E_ERROR );
949
+ return ;
942
950
}
943
951
944
952
if (linelength == 0 && docut ) {
945
- php_error_docref ( NULL , E_WARNING , "Can't force cut when width is zero" );
946
- RETURN_FALSE ;
953
+ zend_throw_exception ( zend_ce_error_exception , "Can't force cut when width is zero" , E_ERROR );
954
+ return ;
947
955
}
948
956
949
957
/* Special case for a single-character break as it needs no
@@ -1133,7 +1141,7 @@ PHPAPI void php_explode_negative_limit(const zend_string *delim, zend_string *st
1133
1141
}
1134
1142
/* }}} */
1135
1143
1136
- /* {{{ proto array|false explode(string separator, string str [, int limit])
1144
+ /* {{{ proto array explode(string separator, string str [, int limit])
1137
1145
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. */
1138
1146
PHP_FUNCTION (explode )
1139
1147
{
@@ -1149,8 +1157,8 @@ PHP_FUNCTION(explode)
1149
1157
ZEND_PARSE_PARAMETERS_END ();
1150
1158
1151
1159
if (ZSTR_LEN (delim ) == 0 ) {
1152
- php_error_docref ( NULL , E_WARNING , "Empty delimiter" );
1153
- RETURN_FALSE ;
1160
+ zend_throw_exception ( zend_ce_error_exception , "Empty delimiter" , E_ERROR );
1161
+ return ;
1154
1162
}
1155
1163
1156
1164
array_init (return_value );
@@ -1623,7 +1631,7 @@ PHPAPI size_t php_dirname(char *path, size_t len)
1623
1631
}
1624
1632
/* }}} */
1625
1633
1626
- /* {{{ proto string|null dirname(string path[, int levels])
1634
+ /* {{{ proto string dirname(string path[, int levels])
1627
1635
Returns the directory name component of the path */
1628
1636
PHP_FUNCTION (dirname )
1629
1637
{
@@ -1648,7 +1656,7 @@ PHP_FUNCTION(dirname)
1648
1656
ZSTR_LEN (ret ) = zend_dirname (ZSTR_VAL (ret ), str_len );
1649
1657
#endif
1650
1658
} else if (levels < 1 ) {
1651
- php_error_docref ( NULL , E_WARNING , "Invalid argument, levels must be >= 1" );
1659
+ zend_throw_exception ( zend_ce_error_exception , "Invalid argument, levels must be >= 1" , E_ERROR );
1652
1660
zend_string_efree (ret );
1653
1661
return ;
1654
1662
} else {
@@ -1817,8 +1825,8 @@ PHP_FUNCTION(stristr)
1817
1825
ZEND_PARSE_PARAMETERS_END ();
1818
1826
1819
1827
if (!ZSTR_LEN (needle )) {
1820
- php_error_docref ( NULL , E_WARNING , "Empty needle" );
1821
- RETURN_FALSE ;
1828
+ zend_throw_exception ( zend_ce_error_exception , "Empty needle" , E_ERROR );
1829
+ return ;
1822
1830
}
1823
1831
1824
1832
haystack_dup = estrndup (ZSTR_VAL (haystack ), ZSTR_LEN (haystack ));
@@ -1858,8 +1866,8 @@ PHP_FUNCTION(strstr)
1858
1866
ZEND_PARSE_PARAMETERS_END ();
1859
1867
1860
1868
if (!ZSTR_LEN (needle )) {
1861
- php_error_docref ( NULL , E_WARNING , "Empty needle" );
1862
- RETURN_FALSE ;
1869
+ zend_throw_exception ( zend_ce_error_exception , "Empty needle" , E_ERROR );
1870
+ return ;
1863
1871
}
1864
1872
1865
1873
found = php_memnstr (ZSTR_VAL (haystack ), ZSTR_VAL (needle ), ZSTR_LEN (needle ), ZSTR_VAL (haystack ) + ZSTR_LEN (haystack ));
@@ -1904,8 +1912,8 @@ PHP_FUNCTION(strpos)
1904
1912
}
1905
1913
1906
1914
if (!ZSTR_LEN (needle )) {
1907
- php_error_docref ( NULL , E_WARNING , "Empty needle" );
1908
- RETURN_FALSE ;
1915
+ zend_throw_exception ( zend_ce_error_exception , "Empty needle" , E_ERROR );
1916
+ return ;
1909
1917
}
1910
1918
1911
1919
found = (char * )php_memnstr (ZSTR_VAL (haystack ) + offset ,
@@ -2198,8 +2206,8 @@ PHP_FUNCTION(chunk_split)
2198
2206
ZEND_PARSE_PARAMETERS_END ();
2199
2207
2200
2208
if (chunklen <= 0 ) {
2201
- php_error_docref ( NULL , E_WARNING , "Chunk length should be greater than zero" );
2202
- RETURN_FALSE ;
2209
+ zend_throw_exception ( zend_ce_error_exception , "Chunk length should be greater than zero" , E_ERROR );
2210
+ return ;
2203
2211
}
2204
2212
2205
2213
if ((size_t )chunklen > ZSTR_LEN (str )) {
@@ -2354,11 +2362,13 @@ PHP_FUNCTION(substr_replace)
2354
2362
(argc == 3 && Z_TYPE_P (from ) == IS_ARRAY ) ||
2355
2363
(argc == 4 && Z_TYPE_P (from ) != Z_TYPE_P (len ))
2356
2364
) {
2365
+ /* TODO can convert to TypeError ? */
2357
2366
php_error_docref (NULL , E_WARNING , "'start' and 'length' should be of same type - numerical or array " );
2358
2367
RETURN_STR_COPY (Z_STR_P (str ));
2359
2368
}
2360
2369
if (argc == 4 && Z_TYPE_P (from ) == IS_ARRAY ) {
2361
2370
if (zend_hash_num_elements (Z_ARRVAL_P (from )) != zend_hash_num_elements (Z_ARRVAL_P (len ))) {
2371
+ /* TODO can convert to Exception ? */
2362
2372
php_error_docref (NULL , E_WARNING , "'start' and 'length' should have the same number of elements" );
2363
2373
RETURN_STR_COPY (Z_STR_P (str ));
2364
2374
}
@@ -2428,6 +2438,7 @@ PHP_FUNCTION(substr_replace)
2428
2438
zend_tmp_string_release (tmp_repl_str );
2429
2439
RETURN_NEW_STR (result );
2430
2440
} else {
2441
+ /* TODO can convert to Exception ? */
2431
2442
php_error_docref (NULL , E_WARNING , "Functionality of 'start' and 'length' as arrays is not implemented" );
2432
2443
RETURN_STR_COPY (Z_STR_P (str ));
2433
2444
}
@@ -3296,7 +3307,7 @@ PHPAPI zend_string *php_str_to_str(const char *haystack, size_t length, const ch
3296
3307
}
3297
3308
/* }}} */
3298
3309
3299
- /* {{{ proto string|false strtr(string str, string from[, string to])
3310
+ /* {{{ proto string strtr(string str, string from[, string to])
3300
3311
Translates characters in str using given translation tables */
3301
3312
PHP_FUNCTION (strtr )
3302
3313
{
@@ -3314,8 +3325,8 @@ PHP_FUNCTION(strtr)
3314
3325
ZEND_PARSE_PARAMETERS_END ();
3315
3326
3316
3327
if (ac == 2 && Z_TYPE_P (from ) != IS_ARRAY ) {
3317
- php_error_docref ( NULL , E_WARNING , "The second argument is not an array" );
3318
- RETURN_FALSE ;
3328
+ zend_type_error ( "The second argument is not an array" );
3329
+ return ;
3319
3330
}
3320
3331
3321
3332
/* shortcut for empty string */
@@ -3363,6 +3374,7 @@ PHP_FUNCTION(strtr)
3363
3374
}
3364
3375
} else {
3365
3376
if (!try_convert_to_string (from )) {
3377
+ zend_type_error ("Cannot convert 'from' into string." );
3366
3378
return ;
3367
3379
}
3368
3380
@@ -5367,7 +5379,7 @@ PHP_FUNCTION(str_repeat)
5367
5379
ZEND_PARSE_PARAMETERS_END ();
5368
5380
5369
5381
if (mult < 0 ) {
5370
- php_error_docref ( NULL , E_WARNING , "Second argument has to be greater than or equal to 0" );
5382
+ zend_throw_exception ( zend_ce_error_exception , "Second argument has to be greater than or equal to 0" , E_ERROR );
5371
5383
return ;
5372
5384
}
5373
5385
@@ -5405,7 +5417,7 @@ PHP_FUNCTION(str_repeat)
5405
5417
}
5406
5418
/* }}} */
5407
5419
5408
- /* {{{ proto array|string|false count_chars(string input [, int mode])
5420
+ /* {{{ proto array|string count_chars(string input [, int mode])
5409
5421
Returns info about what characters are used in input */
5410
5422
PHP_FUNCTION (count_chars )
5411
5423
{
@@ -5425,8 +5437,8 @@ PHP_FUNCTION(count_chars)
5425
5437
ZEND_PARSE_PARAMETERS_END ();
5426
5438
5427
5439
if (mymode < 0 || mymode > 4 ) {
5428
- php_error_docref ( NULL , E_WARNING , "Unknown mode" );
5429
- RETURN_FALSE ;
5440
+ zend_throw_exception ( zend_ce_error_exception , "Unknown mode" , E_ERROR );
5441
+ return ;
5430
5442
}
5431
5443
5432
5444
buf = (const unsigned char * ) ZSTR_VAL (input );
@@ -5614,8 +5626,8 @@ PHP_FUNCTION(substr_count)
5614
5626
ZEND_PARSE_PARAMETERS_END ();
5615
5627
5616
5628
if (needle_len == 0 ) {
5617
- php_error_docref ( NULL , E_WARNING , "Empty substring" );
5618
- RETURN_FALSE ;
5629
+ zend_throw_exception ( zend_ce_error_exception , "Empty substring" , E_ERROR );
5630
+ return ;
5619
5631
}
5620
5632
5621
5633
p = haystack ;
@@ -5636,6 +5648,7 @@ PHP_FUNCTION(substr_count)
5636
5648
length += (haystack_len - offset );
5637
5649
}
5638
5650
if (length < 0 || ((size_t )length > (haystack_len - offset ))) {
5651
+ /* Convert to Exception ? */
5639
5652
php_error_docref (NULL , E_WARNING , "Invalid length value" );
5640
5653
RETURN_FALSE ;
5641
5654
}
@@ -5691,18 +5704,19 @@ PHP_FUNCTION(str_pad)
5691
5704
}
5692
5705
5693
5706
if (pad_str_len == 0 ) {
5694
- php_error_docref ( NULL , E_WARNING , "Padding string cannot be empty" );
5707
+ zend_throw_exception ( zend_ce_error_exception , "Padding string cannot be empty" , E_ERROR );
5695
5708
return ;
5696
5709
}
5697
5710
5698
5711
if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH ) {
5699
- php_error_docref (NULL , E_WARNING , "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH" );
5712
+ zend_throw_exception (zend_ce_error_exception ,
5713
+ "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH" , E_ERROR );
5700
5714
return ;
5701
5715
}
5702
5716
5703
5717
num_pad_chars = pad_length - ZSTR_LEN (input );
5704
5718
if (num_pad_chars >= INT_MAX ) {
5705
- php_error_docref ( NULL , E_WARNING , "Padding length is too long" );
5719
+ zend_throw_exception ( zend_ce_error_exception , "Padding length is too long" , E_ERROR );
5706
5720
return ;
5707
5721
}
5708
5722
@@ -5920,7 +5934,7 @@ PHP_FUNCTION(str_shuffle)
5920
5934
}
5921
5935
/* }}} */
5922
5936
5923
- /* {{{ proto mixed str_word_count(string str, [int format [, string charlist]])
5937
+ /* {{{ proto array|int|null|false str_word_count(string str, [int format [, string charlist]])
5924
5938
Counts the number of words inside a string. If format of 1 is specified,
5925
5939
then the function will return an array containing all the words
5926
5940
found inside the string. If format of 2 is specified, then the function
@@ -5961,6 +5975,10 @@ PHP_FUNCTION(str_word_count)
5961
5975
/* nothing to be done */
5962
5976
break ;
5963
5977
default :
5978
+ /* Not sure how to proceed here
5979
+ zend_throw_exception(zend_ce_error_exception, "Padding string cannot be empty", E_ERROR);
5980
+ return;
5981
+ */
5964
5982
php_error_docref (NULL , E_WARNING , "Invalid format value " ZEND_LONG_FMT , type );
5965
5983
RETURN_FALSE ;
5966
5984
}
@@ -6062,7 +6080,7 @@ PHP_FUNCTION(money_format)
6062
6080
/* }}} */
6063
6081
#endif
6064
6082
6065
- /* {{{ proto array|false str_split(string str [, int split_length])
6083
+ /* {{{ proto array str_split(string str [, int split_length])
6066
6084
Convert a string to an array. If split_length is specified, break the string down into chunks each split_length characters long. */
6067
6085
PHP_FUNCTION (str_split )
6068
6086
{
@@ -6078,8 +6096,8 @@ PHP_FUNCTION(str_split)
6078
6096
ZEND_PARSE_PARAMETERS_END ();
6079
6097
6080
6098
if (split_length <= 0 ) {
6081
- php_error_docref ( NULL , E_WARNING , "The length of each segment must be greater than zero" );
6082
- RETURN_FALSE ;
6099
+ zend_throw_exception ( zend_ce_error_exception , "The length of each segment must be greater than zero" , E_ERROR );
6100
+ return ;
6083
6101
}
6084
6102
6085
6103
@@ -6118,8 +6136,8 @@ PHP_FUNCTION(strpbrk)
6118
6136
ZEND_PARSE_PARAMETERS_END_EX (RETURN_FALSE );
6119
6137
6120
6138
if (!ZSTR_LEN (char_list )) {
6121
- php_error_docref ( NULL , E_WARNING , "The character list cannot be empty" );
6122
- RETURN_FALSE ;
6139
+ zend_throw_exception ( zend_ce_error_exception , "The character list cannot be empty" , E_ERROR );
6140
+ return ;
6123
6141
}
6124
6142
6125
6143
for (haystack_ptr = ZSTR_VAL (haystack ); haystack_ptr < (ZSTR_VAL (haystack ) + ZSTR_LEN (haystack )); ++ haystack_ptr ) {
@@ -6157,8 +6175,8 @@ PHP_FUNCTION(substr_compare)
6157
6175
if (len == 0 ) {
6158
6176
RETURN_LONG (0L );
6159
6177
} else {
6160
- php_error_docref ( NULL , E_WARNING , "The length must be greater than or equal to zero" );
6161
- RETURN_FALSE ;
6178
+ zend_throw_exception ( zend_ce_error_exception , "The length must be greater than or equal to zero" , E_ERROR );
6179
+ return ;
6162
6180
}
6163
6181
}
6164
6182
@@ -6168,6 +6186,7 @@ PHP_FUNCTION(substr_compare)
6168
6186
}
6169
6187
6170
6188
if ((size_t )offset > ZSTR_LEN (s1 )) {
6189
+ /* Candidate to convert to Exception ? */
6171
6190
php_error_docref (NULL , E_WARNING , "The start position cannot exceed initial string length" );
6172
6191
RETURN_FALSE ;
6173
6192
}
0 commit comments