From 1257d4285fb6d4244246094d3862834483f4b960 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sat, 17 Aug 2019 15:32:42 +0200 Subject: [PATCH 01/12] Use Error exceptions instead of warning in some place in string stdlib --- ext/standard/string.c | 99 +++++++++++------- ext/standard/tests/strings/bug33605.phpt | 10 +- ext/standard/tests/strings/bug63943.phpt | 8 +- .../tests/strings/chunk_split_variation5.phpt | Bin 2321 -> 2228 bytes .../tests/strings/chunk_split_variation8.phpt | 14 +-- ext/standard/tests/strings/dirname_error.phpt | 10 +- ext/standard/tests/strings/dirname_multi.phpt | 9 +- ext/standard/tests/strings/explode.phpt | 56 ++++++---- ext/standard/tests/strings/explode1.phpt | 77 +++++++------- ext/standard/tests/strings/str_pad.phpt | Bin 9340 -> 8584 bytes .../tests/strings/str_pad_variation1.phpt | 70 +++++++++++++ ext/standard/tests/strings/str_repeat.phpt | Bin 3492 -> 3069 bytes .../tests/strings/str_repeat_variation1.phpt | 22 ++++ .../strings/str_split_variation6_64bit.phpt | 22 ++-- .../strings/str_split_variation7_64bit.phpt | 26 +++-- ext/standard/tests/strings/stristr.phpt | 31 ++++-- ext/standard/tests/strings/stristr_error.phpt | 20 ++-- .../tests/strings/stristr_variation2.phpt | 28 ++--- ext/standard/tests/strings/strpbrk_error.phpt | 11 +- ext/standard/tests/strings/strpos.phpt | Bin 9009 -> 9387 bytes .../tests/strings/strpos_variation1.phpt | 26 +++++ ext/standard/tests/strings/strstr.phpt | Bin 9649 -> 9807 bytes .../tests/strings/strstr_variation1.phpt | 24 +++++ .../tests/strings/strtr_variation8.phpt | 77 +++++--------- .../tests/strings/substr_compare.phpt | 11 +- .../tests/strings/substr_count_basic.phpt | 26 +++-- ext/standard/tests/strings/wordwrap.phpt | 11 +- .../tests/strings/wordwrap_error.phpt | 11 +- 28 files changed, 443 insertions(+), 256 deletions(-) create mode 100644 ext/standard/tests/strings/str_pad_variation1.phpt create mode 100644 ext/standard/tests/strings/str_repeat_variation1.phpt create mode 100644 ext/standard/tests/strings/strpos_variation1.phpt create mode 100644 ext/standard/tests/strings/strstr_variation1.phpt diff --git a/ext/standard/string.c b/ext/standard/string.c index c2f29baec7732..334e518d28ab2 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -291,6 +291,10 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) / start = 0; } } else if ((size_t)start > ZSTR_LEN(s11)) { + /* Convert to Exception ? + zend_throw_exception(zend_ce_error_exception, "Offset not contained in string", E_ERROR); + return; + */ RETURN_FALSE; } @@ -324,7 +328,7 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) / } /* }}} */ -/* {{{ proto int|false strspn(string str, string mask [, int start [, int len]]) +/* {{{ proto int strspn(string str, string mask [, int start [, int len]]) 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) */ PHP_FUNCTION(strspn) { @@ -332,7 +336,7 @@ PHP_FUNCTION(strspn) } /* }}} */ -/* {{{ proto int|false strcspn(string str, string mask [, int start [, int len]]) +/* {{{ proto int strcspn(string str, string mask [, int start [, int len]]) 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) */ PHP_FUNCTION(strcspn) { @@ -682,6 +686,9 @@ PHP_FUNCTION(nl_langinfo) #endif break; default: + /* TODO Convert to ErrorException + * zend_throw_exception(zend_ce_error_exception, "", E_ERROR); + */ php_error_docref(NULL, E_WARNING, "Item '" ZEND_LONG_FMT "' is not valid", item); RETURN_FALSE; } @@ -718,6 +725,7 @@ PHP_FUNCTION(strcoll) * it needs to be incrementing. * Returns: FAILURE/SUCCESS whether the input was correct (i.e. no range errors) */ +/* TODO (maybe) convert docref errors into ErrorException? */ static inline int php_charmask(const unsigned char *input, size_t len, char *mask) { const unsigned char *end; @@ -907,7 +915,7 @@ PHP_FUNCTION(ltrim) } /* }}} */ -/* {{{ proto string|false wordwrap(string str [, int width [, string break [, bool cut]]]) +/* {{{ proto string wordwrap(string str [, int width [, string break [, bool cut]]]) Wraps buffer to selected number of characters using string break char */ PHP_FUNCTION(wordwrap) { @@ -933,13 +941,13 @@ PHP_FUNCTION(wordwrap) } if (breakchar_len == 0) { - php_error_docref(NULL, E_WARNING, "Break string cannot be empty"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "Break string cannot be empty", E_ERROR); + return; } if (linelength == 0 && docut) { - php_error_docref(NULL, E_WARNING, "Can't force cut when width is zero"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "Can't force cut when width is zero", E_ERROR); + return; } /* 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 } /* }}} */ -/* {{{ proto array|false explode(string separator, string str [, int limit]) +/* {{{ proto array explode(string separator, string str [, int limit]) 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. */ PHP_FUNCTION(explode) { @@ -1145,8 +1153,8 @@ PHP_FUNCTION(explode) ZEND_PARSE_PARAMETERS_END(); if (ZSTR_LEN(delim) == 0) { - php_error_docref(NULL, E_WARNING, "Empty delimiter"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "Empty delimiter", E_ERROR); + return; } array_init(return_value); @@ -1619,7 +1627,7 @@ PHPAPI size_t php_dirname(char *path, size_t len) } /* }}} */ -/* {{{ proto string|null dirname(string path[, int levels]) +/* {{{ proto string dirname(string path[, int levels]) Returns the directory name component of the path */ PHP_FUNCTION(dirname) { @@ -1644,7 +1652,7 @@ PHP_FUNCTION(dirname) ZSTR_LEN(ret) = zend_dirname(ZSTR_VAL(ret), str_len); #endif } else if (levels < 1) { - php_error_docref(NULL, E_WARNING, "Invalid argument, levels must be >= 1"); + zend_throw_exception(zend_ce_error_exception, "Invalid argument, levels must be >= 1", E_ERROR); zend_string_efree(ret); return; } else { @@ -1813,8 +1821,8 @@ PHP_FUNCTION(stristr) ZEND_PARSE_PARAMETERS_END(); if (!ZSTR_LEN(needle)) { - php_error_docref(NULL, E_WARNING, "Empty needle"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "Empty needle", E_ERROR); + return; } haystack_dup = estrndup(ZSTR_VAL(haystack), ZSTR_LEN(haystack)); @@ -1854,8 +1862,8 @@ PHP_FUNCTION(strstr) ZEND_PARSE_PARAMETERS_END(); if (!ZSTR_LEN(needle)) { - php_error_docref(NULL, E_WARNING, "Empty needle"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "Empty needle", E_ERROR); + return; } 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) } if (!ZSTR_LEN(needle)) { - php_error_docref(NULL, E_WARNING, "Empty needle"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "Empty needle", E_ERROR); + return; } found = (char*)php_memnstr(ZSTR_VAL(haystack) + offset, @@ -2194,8 +2202,8 @@ PHP_FUNCTION(chunk_split) ZEND_PARSE_PARAMETERS_END(); if (chunklen <= 0) { - php_error_docref(NULL, E_WARNING, "Chunk length should be greater than zero"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "Chunk length should be greater than zero", E_ERROR); + return; } if ((size_t)chunklen > ZSTR_LEN(str)) { @@ -2350,11 +2358,13 @@ PHP_FUNCTION(substr_replace) (argc == 3 && Z_TYPE_P(from) == IS_ARRAY) || (argc == 4 && Z_TYPE_P(from) != Z_TYPE_P(len)) ) { + /* TODO can convert to TypeError ? */ php_error_docref(NULL, E_WARNING, "'start' and 'length' should be of same type - numerical or array "); RETURN_STR_COPY(Z_STR_P(str)); } if (argc == 4 && Z_TYPE_P(from) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(from)) != zend_hash_num_elements(Z_ARRVAL_P(len))) { + /* TODO can convert to Exception ? */ php_error_docref(NULL, E_WARNING, "'start' and 'length' should have the same number of elements"); RETURN_STR_COPY(Z_STR_P(str)); } @@ -2424,6 +2434,7 @@ PHP_FUNCTION(substr_replace) zend_tmp_string_release(tmp_repl_str); RETURN_NEW_STR(result); } else { + /* TODO can convert to Exception ? */ php_error_docref(NULL, E_WARNING, "Functionality of 'start' and 'length' as arrays is not implemented"); RETURN_STR_COPY(Z_STR_P(str)); } @@ -3292,7 +3303,7 @@ PHPAPI zend_string *php_str_to_str(const char *haystack, size_t length, const ch } /* }}} */ -/* {{{ proto string|false strtr(string str, string from[, string to]) +/* {{{ proto string strtr(string str, string from[, string to]) Translates characters in str using given translation tables */ PHP_FUNCTION(strtr) { @@ -3310,8 +3321,8 @@ PHP_FUNCTION(strtr) ZEND_PARSE_PARAMETERS_END(); if (ac == 2 && Z_TYPE_P(from) != IS_ARRAY) { - php_error_docref(NULL, E_WARNING, "The second argument is not an array"); - RETURN_FALSE; + zend_type_error("The second argument is not an array"); + return; } /* shortcut for empty string */ @@ -3359,6 +3370,7 @@ PHP_FUNCTION(strtr) } } else { if (!try_convert_to_string(from)) { + zend_type_error("Cannot convert 'from' into string."); return; } @@ -5363,7 +5375,7 @@ PHP_FUNCTION(str_repeat) ZEND_PARSE_PARAMETERS_END(); if (mult < 0) { - php_error_docref(NULL, E_WARNING, "Second argument has to be greater than or equal to 0"); + zend_throw_exception(zend_ce_error_exception, "Second argument has to be greater than or equal to 0", E_ERROR); return; } @@ -5401,7 +5413,7 @@ PHP_FUNCTION(str_repeat) } /* }}} */ -/* {{{ proto array|string|false count_chars(string input [, int mode]) +/* {{{ proto array|string count_chars(string input [, int mode]) Returns info about what characters are used in input */ PHP_FUNCTION(count_chars) { @@ -5421,8 +5433,8 @@ PHP_FUNCTION(count_chars) ZEND_PARSE_PARAMETERS_END(); if (mymode < 0 || mymode > 4) { - php_error_docref(NULL, E_WARNING, "Unknown mode"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "Unknown mode", E_ERROR); + return; } buf = (const unsigned char *) ZSTR_VAL(input); @@ -5610,8 +5622,8 @@ PHP_FUNCTION(substr_count) ZEND_PARSE_PARAMETERS_END(); if (needle_len == 0) { - php_error_docref(NULL, E_WARNING, "Empty substring"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "Empty substring", E_ERROR); + return; } p = haystack; @@ -5632,6 +5644,7 @@ PHP_FUNCTION(substr_count) length += (haystack_len - offset); } if (length < 0 || ((size_t)length > (haystack_len - offset))) { + /* Convert to Exception ? */ php_error_docref(NULL, E_WARNING, "Invalid length value"); RETURN_FALSE; } @@ -5687,18 +5700,19 @@ PHP_FUNCTION(str_pad) } if (pad_str_len == 0) { - php_error_docref(NULL, E_WARNING, "Padding string cannot be empty"); + zend_throw_exception(zend_ce_error_exception, "Padding string cannot be empty", E_ERROR); return; } if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH) { - php_error_docref(NULL, E_WARNING, "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH"); + zend_throw_exception(zend_ce_error_exception, + "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH", E_ERROR); return; } num_pad_chars = pad_length - ZSTR_LEN(input); if (num_pad_chars >= INT_MAX) { - php_error_docref(NULL, E_WARNING, "Padding length is too long"); + zend_throw_exception(zend_ce_error_exception, "Padding length is too long", E_ERROR); return; } @@ -5916,7 +5930,7 @@ PHP_FUNCTION(str_shuffle) } /* }}} */ -/* {{{ proto mixed str_word_count(string str, [int format [, string charlist]]) +/* {{{ proto array|int|null|false str_word_count(string str, [int format [, string charlist]]) Counts the number of words inside a string. If format of 1 is specified, then the function will return an array containing all the words found inside the string. If format of 2 is specified, then the function @@ -5957,6 +5971,10 @@ PHP_FUNCTION(str_word_count) /* nothing to be done */ break; default: + /* Not sure how to proceed here + zend_throw_exception(zend_ce_error_exception, "Padding string cannot be empty", E_ERROR); + return; + */ php_error_docref(NULL, E_WARNING, "Invalid format value " ZEND_LONG_FMT, type); RETURN_FALSE; } @@ -6058,7 +6076,7 @@ PHP_FUNCTION(money_format) /* }}} */ #endif -/* {{{ proto array|false str_split(string str [, int split_length]) +/* {{{ proto array str_split(string str [, int split_length]) Convert a string to an array. If split_length is specified, break the string down into chunks each split_length characters long. */ PHP_FUNCTION(str_split) { @@ -6074,8 +6092,8 @@ PHP_FUNCTION(str_split) ZEND_PARSE_PARAMETERS_END(); if (split_length <= 0) { - php_error_docref(NULL, E_WARNING, "The length of each segment must be greater than zero"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "The length of each segment must be greater than zero", E_ERROR); + return; } @@ -6114,8 +6132,8 @@ PHP_FUNCTION(strpbrk) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); if (!ZSTR_LEN(char_list)) { - php_error_docref(NULL, E_WARNING, "The character list cannot be empty"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "The character list cannot be empty", E_ERROR); + return; } for (haystack_ptr = ZSTR_VAL(haystack); haystack_ptr < (ZSTR_VAL(haystack) + ZSTR_LEN(haystack)); ++haystack_ptr) { @@ -6153,8 +6171,8 @@ PHP_FUNCTION(substr_compare) if (len == 0) { RETURN_LONG(0L); } else { - php_error_docref(NULL, E_WARNING, "The length must be greater than or equal to zero"); - RETURN_FALSE; + zend_throw_exception(zend_ce_error_exception, "The length must be greater than or equal to zero", E_ERROR); + return; } } @@ -6164,6 +6182,7 @@ PHP_FUNCTION(substr_compare) } if ((size_t)offset > ZSTR_LEN(s1)) { + /* Candidate to convert to Exception ? */ php_error_docref(NULL, E_WARNING, "The start position cannot exceed initial string length"); RETURN_FALSE; } diff --git a/ext/standard/tests/strings/bug33605.phpt b/ext/standard/tests/strings/bug33605.phpt index 7ba38f94f50d2..4425f8f42c7f8 100644 --- a/ext/standard/tests/strings/bug33605.phpt +++ b/ext/standard/tests/strings/bug33605.phpt @@ -2,10 +2,12 @@ Bug #33605 (substr_compare crashes) --FILE-- getMessage(); +} ?> --EXPECTF-- -Warning: substr_compare(): The length must be greater than or equal to zero in %s on line %d -bool(false) +The length must be greater than or equal to zero diff --git a/ext/standard/tests/strings/bug63943.phpt b/ext/standard/tests/strings/bug63943.phpt index 6018879b24a6d..b3fb916360ba7 100644 --- a/ext/standard/tests/strings/bug63943.phpt +++ b/ext/standard/tests/strings/bug63943.phpt @@ -2,7 +2,11 @@ Bug #63943 (Bad warning text from strpos() on empty needle) --FILE-- getMessage(); +} ?> --EXPECTF-- -Warning: strpos(): Empty needle in %sbug63943.php on line %d +Empty needle diff --git a/ext/standard/tests/strings/chunk_split_variation5.phpt b/ext/standard/tests/strings/chunk_split_variation5.phpt index 8650f2cb92f8093bdebd4098c9f64871aeb50685..c4a3a33e7000588d3b9b8c2c437a48ee1d623ff5 100644 GIT binary patch delta 80 zcmbOzv_){kB^CvRsTb26!a#a eU}>IwnoVQ#N>)xrFhhWSE||f_<&vM5$^`&QUm5KH delta 207 zcmdlYI8kWBC6>wJtd){n;fY0gnR)3}3dtFzdD-#B1v!}|8k$xLlMk|K$SP#!DX11J x%*Uq$TDQr)qBA!OF=getMessage(), "\n"; + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; } } @@ -58,18 +60,14 @@ echo "Done" --EXPECTF-- *** Testing chunk_split() : different 'chunklen' with heredoc 'str' *** -- Iteration 1 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) +Chunk length should be greater than zero -- Iteration 2 -- string(504) "T:::h:::i:::s:::':::s::: :::h:::e:::r:::e:::d:::o:::c::: :::s:::t:::r:::i:::n:::g::: :::w:::i:::t:::h::: ::: ::: :::a:::n:::d::: ::: ::: :::w:::h:::i:::t:::e::: :::s:::p:::a:::c:::e::: :::c:::h:::a:::r:::.::: :::I:::t::: :::h:::a:::s::: :::_:::s:::p:::e:::c:::i:::@:::l::: :::c:::h:::@:::r:::$::: :::2:::2:::2:::2::: :::!:::!:::!:::N:::o:::w::: :::\:::k::: :::a:::s::: :::e:::s:::c:::a:::p:::e::: :::c:::h:::a:::r::: :::t:::o::: :::t:::e:::s:::t::: :::c:::h:::u:::n:::k:::_:::s:::p:::l:::i:::t:::(:::):::" -- Iteration 3 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) +Chunk length should be greater than zero -- Iteration 4 -- string(129) "This's heredoc string with and white space char. @@ -88,7 +86,5 @@ chunk_split():::" -- Iteration 7 -- chunk_split() expects parameter 2 to be int, float given -- Iteration 8 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) +Chunk length should be greater than zero Done diff --git a/ext/standard/tests/strings/dirname_error.phpt b/ext/standard/tests/strings/dirname_error.phpt index 79fac300297fe..951fd9954b816 100644 --- a/ext/standard/tests/strings/dirname_error.phpt +++ b/ext/standard/tests/strings/dirname_error.phpt @@ -8,13 +8,15 @@ Test dirname() function : error conditions echo "*** Testing error conditions ***\n"; // Bad arg -var_dump( dirname("/var/tmp/bar.gz", 0) ); +try { + dirname("/var/tmp/bar.gz", 0); +} catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; +} echo "Done\n"; ?> --EXPECTF-- *** Testing error conditions *** - -Warning: dirname(): Invalid argument, levels must be >= 1 in %s on line %d -NULL +Invalid argument, levels must be >= 1 Done diff --git a/ext/standard/tests/strings/dirname_multi.phpt b/ext/standard/tests/strings/dirname_multi.phpt index febbd0c2930b9..d9fd15ddbab18 100644 --- a/ext/standard/tests/strings/dirname_multi.phpt +++ b/ext/standard/tests/strings/dirname_multi.phpt @@ -11,14 +11,17 @@ if((substr(PHP_OS, 0, 3) == "WIN")) Description: Returns directory name component of path. */ for ($i=0 ; $i<5 ; $i++) { - var_dump(dirname("/foo/bar/baz", $i)); + try { + var_dump(dirname("/foo/bar/baz", $i)); + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } } var_dump(dirname("/foo/bar/baz", PHP_INT_MAX)); ?> Done --EXPECTF-- -Warning: dirname(): Invalid argument, levels must be >= 1 in %sdirname_multi.php on line %d -NULL +Invalid argument, levels must be >= 1 string(8) "/foo/bar" string(4) "/foo" string(1) "/" diff --git a/ext/standard/tests/strings/explode.phpt b/ext/standard/tests/strings/explode.phpt index 84cdcb985fef6..5bede0f1fa5d3 100644 --- a/ext/standard/tests/strings/explode.phpt +++ b/ext/standard/tests/strings/explode.phpt @@ -8,21 +8,40 @@ error_reporting=2047 getMessage() . "\n"; +} +try { + var_dump(explode("", NULL)); +} catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump(explode(NULL, "")); +} catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; +} + +var_dump(explode("a", "")); +var_dump(explode("a", "a")); +var_dump(explode("a", NULL)); +try { + var_dump(explode(NULL, "a")); +} catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; +} +var_dump(explode("abc", "acb")); +var_dump(explode("somestring", "otherstring")); +var_dump(explode("somestring", "otherstring", -1)); +var_dump(explode("a", "aaaaaa")); +var_dump(explode("==", str_repeat("-=".ord(0)."=-", 10))); +var_dump(explode("=", str_repeat("-=".ord(0)."=-", 10))); ////////////////////////////////////// var_dump(explode(":","a lazy dog:jumps:over:",-1)); var_dump(explode(":","a lazy dog:jumps:over", -1)); @@ -39,10 +58,11 @@ array ( 2 => 'f', 3 => '1', 4 => 'd', -)d6bee42a771449205344c0938ad4f035 -bool(false) -bool(false) -bool(false) +) +d6bee42a771449205344c0938ad4f035 +Empty delimiter +Empty delimiter +Empty delimiter array(1) { [0]=> string(0) "" @@ -57,7 +77,7 @@ array(1) { [0]=> string(0) "" } -bool(false) +Empty delimiter array(1) { [0]=> string(3) "acb" diff --git a/ext/standard/tests/strings/explode1.phpt b/ext/standard/tests/strings/explode1.phpt index de3049a47b3a8..826f2355670f6 100644 --- a/ext/standard/tests/strings/explode1.phpt +++ b/ext/standard/tests/strings/explode1.phpt @@ -32,12 +32,29 @@ $string = "1234NULL23abcd00000TRUEFALSE-11.234444true-11.24%PHP%ZEND"; */ $counter = 1; foreach($delimiters as $delimiter) { - echo "-- Iteration $counter --\n"; - var_dump( explode($delimiter, $string, -1) ); - var_dump( explode($delimiter, $string, 0) ); - var_dump( explode($delimiter, $string, 1) ); - var_dump( explode($delimiter, $string, 2) ); - $counter++; + echo "-- Iteration $counter --\n"; + + try { + var_dump( explode($delimiter, $string, -1) ); + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } + try { + var_dump( explode($delimiter, $string, 0) ); + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } + try { + var_dump( explode($delimiter, $string, 1) ); + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } + try { + var_dump( explode($delimiter, $string, 2) ); + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } + $counter++; } echo "\n*** Testing explode() with miscelleneous input arguments ***\n"; @@ -82,31 +99,15 @@ echo "Done\n"; --EXPECTF-- *** Testing explode() for basic operations *** -- Iteration 1 -- - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) +Empty delimiter +Empty delimiter +Empty delimiter +Empty delimiter -- Iteration 2 -- - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) +Empty delimiter +Empty delimiter +Empty delimiter +Empty delimiter -- Iteration 3 -- array(1) { [0]=> @@ -208,18 +209,10 @@ array(2) { string(56) "234NULL23abcd00000TRUEFALSE-11.234444true-11.24%PHP%ZEND" } -- Iteration 7 -- - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) - -Warning: explode(): Empty delimiter in %s on line %d -bool(false) +Empty delimiter +Empty delimiter +Empty delimiter +Empty delimiter -- Iteration 8 -- array(2) { [0]=> diff --git a/ext/standard/tests/strings/str_pad.phpt b/ext/standard/tests/strings/str_pad.phpt index be4c9ed9428695dd25d532e0eabca37dddc1580f..fe1b111f20a74d9094d664bb321c2a93e4e9381e 100644 GIT binary patch delta 531 zcmez4(c!$|BNL;-0Fb0nZ+k>W)@R7G}Td1 z0Ltc-=B5^9CUYqOfuX6MDVp$PSr$2FO>3^nek{h!KqZr#S=7Pw8Wx$!S6Or?^Rwzr z_5$KoRxPl)1FT{|`>(MYP3B^Yn4G|-Klve>!Q|a+T0lB#@<&eh$#v|!VEP<8ACL}U z2iaW9RXaJ4Nn-LddC|>L96U@+F?o~IxU~3V@|3K(xJrsD6{ZZyLKucd7Elpm6R3!Zv8Ij!r@p>| zow;sOW{HAhu(PKp7bhpsFeN33OlodHNu@$@Nl|8AIv1)XV4h#7kB^RmgaXhI5EEU= zWP4^Q0W@uflM9)Jxse1XXEIBp@Ee%rgpuSSOik;_3z>~U9=^`34x$)YWI!&3fXR|9 zhDba&79%8H35yXwOd*&yG@D$-qN9u?rfJQkQjnMu5Amsjt%8!Rk~NpU*5p?#Moe4^ zlVw;VCYQ15PS)VinS7a5YjPcj1Ss?wERY9Sat9Ei8lf>qHc15PilQ^}QfqExz zWEJN&G|~Zw3($BFp992KQUZEq9+$ynMmD|4f4MlA6@YwCZW%_m&8ggHnCne76_gnM zH@xas;)1wFgRUa=18cpeKDzHMVGaUC7d%YhqLUYhh{m9X7hKL32vBs`+JaRgi5eOp z8;>v_AwF49R6+vP0u)J6X{eb9s|?LxhE6UNm1G6WPj(bmK{p1W%u!elqHJ@bpdZub z0>MK5$&VD|MZyz{@_<>-3X}!ofeBPY(@J47qoSO;LS~+VYOz9oo3Kti} TYV8%BWiZVJ=WCbzyi_g#gd9wH diff --git a/ext/standard/tests/strings/str_pad_variation1.phpt b/ext/standard/tests/strings/str_pad_variation1.phpt new file mode 100644 index 0000000000000..1ebf1b2825bd3 --- /dev/null +++ b/ext/standard/tests/strings/str_pad_variation1.phpt @@ -0,0 +1,70 @@ +--TEST-- +str_pad() function: usage variations - Non printable chars +--INI-- +precision=14 +--FILE-- + sizeof(input_string) + 16, // pad_length > sizeof(input_string) +]; + +$pad_string = "="; + +/*loop through to use each variant of $pad_length on + each element of $input_strings array */ +foreach ($pad_lengths as $pad_length ) { + // default pad_string & pad_type + var_dump( bin2hex( str_pad($string, $pad_length) ) ); + // default pad_type + var_dump( bin2hex( str_pad($string, $pad_length, $pad_string) ) ); + var_dump( bin2hex( str_pad($string, $pad_length, $pad_string, STR_PAD_LEFT) ) ); + var_dump( bin2hex( str_pad($string, $pad_length, $pad_string, STR_PAD_RIGHT) ) ); + var_dump( bin2hex( str_pad($string, $pad_length, $pad_string, STR_PAD_BOTH) ) ); +} + +?> + +DONE +--EXPECT-- +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(10) "00ff80ea8f" +string(18) "00ff80ea8f20202020" +string(18) "00ff80ea8f3d3d3d3d" +string(18) "3d3d3d3d00ff80ea8f" +string(18) "00ff80ea8f3d3d3d3d" +string(18) "3d3d00ff80ea8f3d3d" +string(20) "00ff80ea8f2020202020" +string(20) "00ff80ea8f3d3d3d3d3d" +string(20) "3d3d3d3d3d00ff80ea8f" +string(20) "00ff80ea8f3d3d3d3d3d" +string(20) "3d3d00ff80ea8f3d3d3d" +string(32) "00ff80ea8f2020202020202020202020" +string(32) "00ff80ea8f3d3d3d3d3d3d3d3d3d3d3d" +string(32) "3d3d3d3d3d3d3d3d3d3d3d00ff80ea8f" +string(32) "00ff80ea8f3d3d3d3d3d3d3d3d3d3d3d" +string(32) "3d3d3d3d3d00ff80ea8f3d3d3d3d3d3d" + +DONE diff --git a/ext/standard/tests/strings/str_repeat.phpt b/ext/standard/tests/strings/str_repeat.phpt index 766bea1f9c32df17825d32ffe184a7be19a54dbd..b73e58175a425d0aca61fe8f5ec41537b50af252 100644 GIT binary patch delta 154 zcmZ1?{a1X$Kc>liEJ}Pac}mt?B}J7A)m#b+3X^SEq!_IyN3qC9)G8z=mLz8=XvDY{ z73CMXRwSnulw{`TDX64sLKG{cCTHXWxw>}gsU^Ot#l?x~sT!IJdJ0NlLuSl9xpZ}1BLZBVLv(eyCjVoS+q{kC5IZB+WC0chAQ{4I!VXmj0JtM6O#lD@ delta 529 zcmew>zC?P%Kc>kCnC0q|^K%PwQY#dSONuh{(u)<6^Ycm)GxLCK1ug{$$S=uAEmA1S zNX%0(*Gdf`(-hQ=)fLh+%Tn|3m|zUl%f-c&nw*iZpcIoAlLvIVLP%T)Mih5dp5wA#R)ZGCyXgJPf%YA+KR% zsHvdD(9rnm^}qk9loA0YEI=Jfljm`(h=(T@fnv@I6q~R>)U;BVe2CjbMj +DONE +--EXPECT-- +bool(true) +string(42) "008081eaebfeff008081eaebfeff008081eaebfeff" +string(42) "008081eaebfeff008081eaebfeff008081eaebfeff" +DONE diff --git a/ext/standard/tests/strings/str_split_variation6_64bit.phpt b/ext/standard/tests/strings/str_split_variation6_64bit.phpt index 583c7db3cf65f..79beb36427f59 100644 --- a/ext/standard/tests/strings/str_split_variation6_64bit.phpt +++ b/ext/standard/tests/strings/str_split_variation6_64bit.phpt @@ -36,17 +36,19 @@ $values = array ( //loop through each element of $values for 'split_length' for($count = 0; $count < count($values); $count++) { - echo "-- Iteration ".($count + 1)." --\n"; - var_dump( str_split($str, $values[$count]) ); + echo "-- Iteration ".($count + 1)." --\n"; + try { + var_dump( str_split($str, $values[$count]) ); + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } } echo "Done" ?> ---EXPECTF-- +--EXPECT-- *** Testing str_split() : different intger values for 'split_length' *** -- Iteration 1 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero -- Iteration 2 -- array(42) { [0]=> @@ -135,9 +137,7 @@ array(42) { string(1) "t" } -- Iteration 3 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero -- Iteration 4 -- array(1) { [0]=> @@ -161,7 +161,5 @@ array(1) { string(42) "This is a string with 123 & escape char \t" } -- Iteration 8 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero Done diff --git a/ext/standard/tests/strings/str_split_variation7_64bit.phpt b/ext/standard/tests/strings/str_split_variation7_64bit.phpt index bff61adb30244..9c792dfd86f97 100644 --- a/ext/standard/tests/strings/str_split_variation7_64bit.phpt +++ b/ext/standard/tests/strings/str_split_variation7_64bit.phpt @@ -18,7 +18,7 @@ if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); * passing different integer values for 'split_length' and heredoc string as 'str' argument to str_split() */ -echo "*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***\n"; +echo "*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' ***\n"; //Initialise variables $str = <<getMessage() . "\n"; + } } echo "Done" ?> ---EXPECTF-- -*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' *** +--EXPECT-- +*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' *** -- Iteration 1 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero -- Iteration 2 -- array(30) { [0]=> @@ -113,9 +115,7 @@ array(30) { string(1) "." } -- Iteration 3 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero -- Iteration 4 -- array(1) { [0]=> @@ -139,7 +139,5 @@ array(1) { string(30) "string with 123,escape char ." } -- Iteration 8 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero Done diff --git a/ext/standard/tests/strings/stristr.phpt b/ext/standard/tests/strings/stristr.phpt index 92cfa09eb1e17..fd11e9bdce50f 100644 --- a/ext/standard/tests/strings/stristr.phpt +++ b/ext/standard/tests/strings/stristr.phpt @@ -8,12 +8,29 @@ stristr() function var_dump(stristr("tEsT sTrInG", "t S")); var_dump(stristr("tEsT sTrInG", "g")); var_dump(md5(stristr("te".chr(0)."st", chr(0)))); - var_dump(@stristr("", "")); - var_dump(@stristr("a", "")); - var_dump(@stristr("", "a")); - var_dump(md5(@stristr("\\\\a\\", "\\a"))); + + try { + var_dump( stristr("", "") ); + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } + + try { + var_dump( stristr("a", "") ); + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } + + try { + var_dump( stristr("", "a") ); + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } + var_dump(md5(stristr("\\\\a\\", "\\a"))); var_dump(stristr("tEsT sTrInG", " ")); ?> + +DONE --EXPECTF-- string(11) "tEsT sTrInG" string(6) "sTrInG" @@ -21,8 +38,10 @@ string(6) "sTrInG" string(8) "T sTrInG" string(1) "G" string(32) "7272696018bdeb2c9a3f8d01fc2a9273" -bool(false) -bool(false) +Empty needle +Empty needle bool(false) string(32) "6ec19f52f0766c463f3bb240f4396913" string(7) " sTrInG" + +DONE diff --git a/ext/standard/tests/strings/stristr_error.phpt b/ext/standard/tests/strings/stristr_error.phpt index a7b683d3b8681..cbfc1ddd99c9f 100644 --- a/ext/standard/tests/strings/stristr_error.phpt +++ b/ext/standard/tests/strings/stristr_error.phpt @@ -9,10 +9,18 @@ Test stristr() function : error conditions echo "*** Testing stristr() : error conditions ***\n"; echo "\n-- Testing stristr() function with empty haystack --\n"; -var_dump( stristr(NULL, "") ); +try { + stristr(NULL, ""); +} catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; +} echo "\n-- Testing stristr() function with empty needle --\n"; -var_dump( stristr("Hello World", "") ); +try { + stristr("Hello World", ""); +} catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; +} ?> ===DONE=== @@ -20,12 +28,8 @@ var_dump( stristr("Hello World", "") ); *** Testing stristr() : error conditions *** -- Testing stristr() function with empty haystack -- - -Warning: stristr(): Empty needle in %s on line %d -bool(false) +Empty needle -- Testing stristr() function with empty needle -- - -Warning: stristr(): Empty needle in %s on line %d -bool(false) +Empty needle ===DONE=== diff --git a/ext/standard/tests/strings/stristr_variation2.phpt b/ext/standard/tests/strings/stristr_variation2.phpt index fd842d1106441..af9148f9e3929 100644 --- a/ext/standard/tests/strings/stristr_variation2.phpt +++ b/ext/standard/tests/strings/stristr_variation2.phpt @@ -76,7 +76,9 @@ foreach($inputs as $input) { var_dump( stristr("Hello World", $input) ); } catch (TypeError $e) { echo $e->getMessage(), "\n"; - } + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } $count ++; } @@ -109,33 +111,21 @@ stristr() expects parameter 2 to be string, array given -- Iteration 11 -- bool(false) -- Iteration 12 -- - -Warning: stristr(): Empty needle in %s on line %d -bool(false) +Empty needle -- Iteration 13 -- bool(false) -- Iteration 14 -- - -Warning: stristr(): Empty needle in %s on line %d -bool(false) +Empty needle -- Iteration 15 -- - -Warning: stristr(): Empty needle in %s on line %d -bool(false) +Empty needle -- Iteration 16 -- - -Warning: stristr(): Empty needle in %s on line %d -bool(false) +Empty needle -- Iteration 17 -- bool(false) -- Iteration 18 -- stristr() expects parameter 2 to be string, resource given -- Iteration 19 -- - -Warning: stristr(): Empty needle in %s on line %d -bool(false) +Empty needle -- Iteration 20 -- - -Warning: stristr(): Empty needle in %s on line %d -bool(false) +Empty needle ===DONE=== diff --git a/ext/standard/tests/strings/strpbrk_error.phpt b/ext/standard/tests/strings/strpbrk_error.phpt index cce843c2f1858..f55a3967aad44 100644 --- a/ext/standard/tests/strings/strpbrk_error.phpt +++ b/ext/standard/tests/strings/strpbrk_error.phpt @@ -13,7 +13,12 @@ echo "*** Testing strpbrk() : error conditions ***\n"; $haystack = 'This is a Simple text.'; echo "\n-- Testing strpbrk() function with empty second argument --\n"; -var_dump( strpbrk($haystack, '') ); + +try { + strpbrk($haystack, ''); +} catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; +} ?> ===DONE=== @@ -21,7 +26,5 @@ var_dump( strpbrk($haystack, '') ); *** Testing strpbrk() : error conditions *** -- Testing strpbrk() function with empty second argument -- - -Warning: strpbrk(): The character list cannot be empty in %s on line %d -bool(false) +The character list cannot be empty ===DONE=== diff --git a/ext/standard/tests/strings/strpos.phpt b/ext/standard/tests/strings/strpos.phpt index 4640b670f316314e6a8720da849fa7cb8c84bc38..8983c33f943939f0c609c4841c3c16767cddc382 100644 GIT binary patch delta 1839 zcmdn!w%T(;6cZ!Y#sHCGnWkVqj zO{AJjCr@M)-h7N{5!2)}RvkgG=Sqqyq25$bm~0>-HF+JYU?|AfL<9^xa6lme3=o`Q z1U7H;K2{$l4rp*HO>UG`oNUM;FQA}+>;$kQq$ihhD9R%_A*8Y(6&yWCu`+o*hbA*n z&E$QolAAwqL@`eG;*ygE*;JHTQd*R!pyZL7lasHbP@Z3ulLCw=pwabQW*}7}2sKEO z54jYfQac>weSq$ynlmTQ6}SQ|zx0KK zCQlKRb)q~}CvOm3Gx;#9$mHLOB8W7q>P6MCRh{fDVoa^{q&j(~h#9pElb-xQgx8z$ zVC3Smx8rj0_j8>j+92tgTToJ|ke8a8l9S4X%-K9$^e-b1vdH8M;_p!eHvg7TWK%;{ yf?@&+XYy6~5){po+Z3u$ZO_ar(J%c2*o;(FSr2da3bgc delta 1256 zcmbVLO-~b16s4`u^wAdR2LqOtJ41zzPy&S(g@7*9NCblmV?vsk0j74eovAYeNMcji zy3ufV{s1?`MAO72xYxv(xHB$HOiVQ4A1J;zv=f4;jk9^@-FNQ2=YGu2?8_@J7M+zf zNx!|aS}Y~tqG9SK%}5Bs5D0<@;uJaIQTppEdzAj@o28%S&kidAslIkScH)hevrYiK zA2^NAS~{ve_cdk<;yxe3El)2>{s_Jc5Paj|ao-cgHgd*QCS}}pan%K~=)kDA2j8}K zpN{&v#fPLk#-S5L3 zrI-DJhseu$4TP+Uy8>VJwZ%`NGZ1d3m1akf4@7V;*hndbiX9-Cgk`N*D##Cj_F7Tz81$~1lA=-!nwgh%F!PcM6UimTgyp=X8<0$9Ra!xu zdcZWb>4_0>m>r|3b9He35TwS&>mXeN>2dL%#ZINubfAZ&P#p`Jp_q!M8ldIC(28;` zo1#($a!no#u&e_h=`u(LRlk3W=OlFl3P&!PUFnKODWcB%MuSl9kW?1aT5B7fa>_sIt6LkZ~{`!{@vY zw<4b#+P+h`<5tfHu9VnQUfgZ$@0GQS2F zsA+TS+xMRbwH@j|x "; +var_dump( strpos($string, chr(128)) ); +echo bin2hex( chr(255) ) ." => "; +var_dump( strpos($string, chr(255), 3) ); +echo bin2hex( chr(256) ) ." => "; +var_dump( strpos($string, chr(256)) ); + +?> + +DONE +--EXPECT-- +-- Positions of some chars in the string '008081eaebfeff' are as follows -- +80 => int(1) +ff => int(6) +00 => int(0) + +DONE diff --git a/ext/standard/tests/strings/strstr.phpt b/ext/standard/tests/strings/strstr.phpt index 6bdc3feab1a31c62f302f5fe2d92ba5e917439fe..4c2ead3ce5bd16fa9ad931f638c57c46447c2038 100644 GIT binary patch delta 1664 zcmdn!ecoq722(v(Nl~RjHJ1VqlqD9$r?9HkyprC*VLQpVH{>Uvgxr0?O0K_38 z+(63khaK1;uG+~5n8YWam6q9jmerpLDKsa`aLD-)VG({yP$Fou6^8<~jkFUGn_R%b zNo`{*IZT`=_x$EH9Lt!wkpuN3w`e3V`NtSwOETo77~~89Od}xE{X%_wXpp@?ruzWh zPBo`b-pF$WC2;t8UH(kA6ELr* zJk20SC`Q={iduZ7rzOe7r@b8)my5rj>*QquPbFP*3rZ>#@={Y%a#FdFIhz*=asOB;=)a3HsZ#Gh#Nr{u5=@U8;kTG81J1t7_Ep+VBmgp?sv}l?s>ew{QS~JMY(!g zw{NW7s@7CE>$tY~R7$6SQVp~P@|R2fpSSW-_kF#m;YSJ(~v&R{;fV!E(e(QOB^*=0r-NLqM6N!V<4Mw^z$Z0=+SoN9sGiMbBQw?TeRGktb0 zpBDveDapbjcTCsh%mKa*4zC*RWF`{=jJ7(Mlu0K+w++x8Sm&0-?+8J@9zRl728B`? zD6(kk*p#nPit}66D#-wvnL0WdvGKkDfOiQ zPiG$Y8R1h#t@pT3Cpz+}Q=FjH#6(9{U@a6WNs09sZi%CgSZi1L1F;MEPus10g f2$<%DsT~!YnRI=pvlnc{Z@9O9L_1qS "; +var_dump( bin2hex( strstr($string, chr(128) ) ) ); +echo bin2hex( chr(255) ) ." => "; +var_dump( bin2hex( strstr($string, chr(255) ) ) ); +echo bin2hex( chr(256) ) ." => "; +var_dump( bin2hex( strstr($string, chr(256) ) ) ); + +?> + +DONE +--EXPECT-- +-- Positions of some chars in the string '008081eaebfeff' are as follows -- +80 => string(12) "8081eaebfeff" +ff => string(2) "ff" +00 => string(14) "008081eaebfeff" + +DONE diff --git a/ext/standard/tests/strings/strtr_variation8.phpt b/ext/standard/tests/strings/strtr_variation8.phpt index 8d29db1cc3afc..2e2843335d477 100644 --- a/ext/standard/tests/strings/strtr_variation8.phpt +++ b/ext/standard/tests/strings/strtr_variation8.phpt @@ -75,10 +75,15 @@ $replace_pairs_arr = array ( // loop through with each element of the $replace_pairs array to test strtr() function $count = 1; for($index = 0; $index < count($replace_pairs_arr); $index++) { - echo "\n-- Iteration $count --\n"; - $replace_pairs = $replace_pairs_arr[$index]; - var_dump( strtr($str, $replace_pairs) ); - $count ++; + echo "\n-- Iteration $count --\n"; + $replace_pairs = $replace_pairs_arr[$index]; + try { + var_dump( strtr($str, $replace_pairs) ); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + + $count ++; } fclose($file_handle); //closing the file handle @@ -89,34 +94,22 @@ echo "*** Done ***"; *** Testing strtr() function: with unexpected inputs for 'replace_pairs' *** -- Iteration 1 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 2 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 3 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 4 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 5 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 6 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 7 -- string(6) "012atm" @@ -128,52 +121,32 @@ string(6) "012atm" string(6) "122atm" -- Iteration 10 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 11 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 12 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 13 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 14 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 15 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 16 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 17 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 18 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array -- Iteration 19 -- - -Warning: strtr(): The second argument is not an array in %s on line %d -bool(false) +The second argument is not an array *** Done *** diff --git a/ext/standard/tests/strings/substr_compare.phpt b/ext/standard/tests/strings/substr_compare.phpt index 9d4bac4ba9938..99ed269585e4a 100644 --- a/ext/standard/tests/strings/substr_compare.phpt +++ b/ext/standard/tests/strings/substr_compare.phpt @@ -13,7 +13,12 @@ var_dump(substr_compare("abcde", "abc", 5, 1)); var_dump(substr_compare("abcde", "abcdef", -10, 10) < 0); var_dump(substr_compare("abcde", "abc", 0, 0)); echo "Test\n"; -var_dump(substr_compare("abcde", "abc", 0, -1)); + +try { + substr_compare("abcde", "abc", 0, -1); +} catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; +} var_dump(substr_compare("abcde", "abc", -1, NULL, -5) > 0); echo "Done\n"; @@ -29,8 +34,6 @@ int(-1) bool(true) int(0) Test - -Warning: substr_compare(): The length must be greater than or equal to zero in %s on line %d -bool(false) +The length must be greater than or equal to zero bool(true) Done diff --git a/ext/standard/tests/strings/substr_count_basic.phpt b/ext/standard/tests/strings/substr_count_basic.phpt index 4023a774d8e74..d52d6a3bbde58 100644 --- a/ext/standard/tests/strings/substr_count_basic.phpt +++ b/ext/standard/tests/strings/substr_count_basic.phpt @@ -4,17 +4,25 @@ Test substr_count() function (basic) getMessage() . "\n"; +} +try { + substr_count("a", ""); +} catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; +} +var_dump(substr_count("", "a")); +var_dump(substr_count("", "a")); +var_dump(substr_count("", chr(0))); $a = str_repeat("abcacba", 100); -var_dump(@substr_count($a, "bca")); +var_dump(substr_count($a, "bca")); $a = str_repeat("abcacbabca", 100); -var_dump(@substr_count($a, "bca")); +var_dump(substr_count($a, "bca")); var_dump(substr_count($a, "bca", 200)); var_dump(substr_count($a, "bca", 200, 50)); var_dump(substr_count($a, "bca", -200)); @@ -26,8 +34,8 @@ echo "Done\n"; ?> --EXPECT-- ***Testing basic operations *** -bool(false) -bool(false) +Empty substring +Empty substring int(0) int(0) int(0) diff --git a/ext/standard/tests/strings/wordwrap.phpt b/ext/standard/tests/strings/wordwrap.phpt index 543c41fdd97f6..23958b17ff3f5 100644 --- a/ext/standard/tests/strings/wordwrap.phpt +++ b/ext/standard/tests/strings/wordwrap.phpt @@ -27,10 +27,17 @@ $tests = <<getMessage() . "\n"; +} --EXPECT-- OK +Break string cannot be empty diff --git a/ext/standard/tests/strings/wordwrap_error.phpt b/ext/standard/tests/strings/wordwrap_error.phpt index ad75461d3d19b..fe79daecfac62 100644 --- a/ext/standard/tests/strings/wordwrap_error.phpt +++ b/ext/standard/tests/strings/wordwrap_error.phpt @@ -26,7 +26,12 @@ echo "-- width = 0 & cut = true --\n"; // width as zero and cut as true $width = 0; $cut = true; -var_dump( wordwrap($str, $width, $break, $cut) ); + +try { + wordwrap($str, $width, $break, $cut); +} catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; +} echo "-- width = -10 & cut = false --\n"; // width as -ne and cut as false @@ -49,9 +54,7 @@ echo "Done\n"; -- width = 0 & cut = false -- string(39) "testing
\nwordwrap
\nfunction" -- width = 0 & cut = true -- - -Warning: wordwrap(): Can't force cut when width is zero in %s on line %d -bool(false) +Can't force cut when width is zero -- width = -10 & cut = false -- string(39) "testing
\nwordwrap
\nfunction" -- width = -10 & cut = true -- From 1084c4e25eb2341842a143bd0d470c3e645bfa19 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sat, 17 Aug 2019 16:41:33 +0200 Subject: [PATCH 02/12] Fix tests --- ext/mbstring/tests/bug73646.phpt | 12 ++++++--- ext/opcache/tests/bug70207.phpt | 5 +++- .../tests/strings/str_split_variation6.phpt | 27 +++++++++---------- .../tests/strings/str_split_variation7.phpt | 27 +++++++++---------- 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/ext/mbstring/tests/bug73646.phpt b/ext/mbstring/tests/bug73646.phpt index 7ac824d69cb4d..f2adec521d934 100644 --- a/ext/mbstring/tests/bug73646.phpt +++ b/ext/mbstring/tests/bug73646.phpt @@ -7,10 +7,16 @@ if (!function_exists('mb_ereg')) die('skip mbregex support not available'); ?> --FILE-- getMessage() . "\n"; +} -$v1=str_repeat("#", -1); var_dump(mb_ereg_search_init($v1)); ?> ---EXPECTF-- -Warning: str_repeat(): Second argument has to be greater than or equal to 0 in %sbug73646.php on line %d +--EXPECT-- +Second argument has to be greater than or equal to 0 bool(true) diff --git a/ext/opcache/tests/bug70207.phpt b/ext/opcache/tests/bug70207.phpt index 806ea7535b67e..ff0d4432da53c 100644 --- a/ext/opcache/tests/bug70207.phpt +++ b/ext/opcache/tests/bug70207.phpt @@ -14,7 +14,10 @@ function bar() { } function foo() { try { return bar(); } - finally { @str_repeat("foo", -10); } + finally { + try { @str_repeat("foo", -10); } + catch (\ErrorException $e) {} + } } var_dump(foo()); diff --git a/ext/standard/tests/strings/str_split_variation6.phpt b/ext/standard/tests/strings/str_split_variation6.phpt index 1aea668026310..4ddf3a48ac97e 100644 --- a/ext/standard/tests/strings/str_split_variation6.phpt +++ b/ext/standard/tests/strings/str_split_variation6.phpt @@ -18,7 +18,7 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); * passing different integer values for 'split_length' argument to str_split() */ -echo "*** Testing str_split() : different intger values for 'split_length' ***\n"; +echo "*** Testing str_split() : different integer values for 'split_length' ***\n"; //Initialise variables $str = 'This is a string with 123 & escape char \t'; @@ -35,17 +35,20 @@ $values = array ( //loop through each element of $values for 'split_length' for($count = 0; $count < count($values); $count++) { - echo "-- Iteration ".($count + 1)." --\n"; - var_dump( str_split($str, $values[$count]) ); + echo "-- Iteration ".($count + 1)." --\n"; + + try { + var_dump( str_split($str, $values[$count]) ); + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } } echo "Done" ?> ---EXPECTF-- -*** Testing str_split() : different intger values for 'split_length' *** +--EXPECT-- +*** Testing str_split() : different integer values for 'split_length' *** -- Iteration 1 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero -- Iteration 2 -- array(42) { [0]=> @@ -134,9 +137,7 @@ array(42) { string(1) "t" } -- Iteration 3 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero -- Iteration 4 -- array(1) { [0]=> @@ -155,7 +156,5 @@ array(1) { string(42) "This is a string with 123 & escape char \t" } -- Iteration 7 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero Done diff --git a/ext/standard/tests/strings/str_split_variation7.phpt b/ext/standard/tests/strings/str_split_variation7.phpt index 1a2471a20a88b..84f9deadef815 100644 --- a/ext/standard/tests/strings/str_split_variation7.phpt +++ b/ext/standard/tests/strings/str_split_variation7.phpt @@ -18,7 +18,7 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); * passing different integer values for 'split_length' and heredoc string as 'str' argument to str_split() */ -echo "*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***\n"; +echo "*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' ***\n"; //Initialise variables $str = <<getMessage() . "\n"; + } } echo "Done" ?> ---EXPECTF-- -*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' *** +--EXPECT-- +*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' *** -- Iteration 1 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero -- Iteration 2 -- array(30) { [0]=> @@ -112,9 +115,7 @@ array(30) { string(1) "." } -- Iteration 3 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero -- Iteration 4 -- array(1) { [0]=> @@ -133,7 +134,5 @@ array(1) { string(30) "string with 123,escape char ." } -- Iteration 7 -- - -Warning: str_split(): The length of each segment must be greater than zero in %s on line %d -bool(false) +The length of each segment must be greater than zero Done From 0aefa924e33f58e32fe04b1e6c80eab05e9300e0 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sat, 17 Aug 2019 16:45:47 +0200 Subject: [PATCH 03/12] Fix Win test --- ext/standard/tests/strings/dirname_multi_win.phpt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ext/standard/tests/strings/dirname_multi_win.phpt b/ext/standard/tests/strings/dirname_multi_win.phpt index 4fed5895e634f..636196492693d 100644 --- a/ext/standard/tests/strings/dirname_multi_win.phpt +++ b/ext/standard/tests/strings/dirname_multi_win.phpt @@ -10,6 +10,14 @@ if((substr(PHP_OS, 0, 3) != "WIN")) /* Prototype: string dirname ( string $path [, int nb]); Description: Returns directory name component of path. */ + +for ($i=0 ; $i<5 ; $i++) { + try { + var_dump(dirname("/foo/bar/baz", $i)); + } catch (\ErrorException $e) { + echo $e->getMessage() . "\n"; + } +} for ($i=0 ; $i<5 ; $i++) { var_dump(dirname("/foo/bar/baz", $i)); } @@ -18,9 +26,8 @@ var_dump(dirname("g:/foo/bar/baz", PHP_INT_MAX)); var_dump(dirname("g:foo/bar/baz", PHP_INT_MAX)); ?> Done ---EXPECTF-- -Warning: dirname(): Invalid argument, levels must be >= 1 in %sdirname_multi_win.php on line %d -NULL +--EXPECT-- +Invalid argument, levels must be >= 1 string(8) "/foo/bar" string(4) "/foo" string(1) "\" From 7e7af36c929de27b9ec16ddcd2663a30f00c5652 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sun, 18 Aug 2019 13:41:42 +0200 Subject: [PATCH 04/12] Use Error --- ext/standard/string.c | 42 +++++++++--------- ext/standard/tests/strings/bug33605.phpt | 2 +- ext/standard/tests/strings/bug63943.phpt | 2 +- .../tests/strings/chunk_split_variation5.phpt | Bin 2228 -> 2219 bytes .../tests/strings/chunk_split_variation8.phpt | 2 +- ext/standard/tests/strings/dirname_error.phpt | 2 +- ext/standard/tests/strings/dirname_multi.phpt | 2 +- .../tests/strings/dirname_multi_win.phpt | 2 +- ext/standard/tests/strings/explode.phpt | 8 ++-- ext/standard/tests/strings/explode1.phpt | 8 ++-- ext/standard/tests/strings/str_pad.phpt | 6 +-- ext/standard/tests/strings/str_repeat.phpt | Bin 3069 -> 3060 bytes .../tests/strings/str_split_variation6.phpt | 2 +- .../strings/str_split_variation6_64bit.phpt | 2 +- .../tests/strings/str_split_variation7.phpt | 2 +- .../strings/str_split_variation7_64bit.phpt | 2 +- ext/standard/tests/strings/stristr.phpt | 6 +-- ext/standard/tests/strings/stristr_error.phpt | 4 +- .../tests/strings/stristr_variation2.phpt | 2 +- ext/standard/tests/strings/strpbrk_error.phpt | 8 +--- ext/standard/tests/strings/strpos.phpt | Bin 9387 -> 9234 bytes ext/standard/tests/strings/strstr.phpt | Bin 9807 -> 9672 bytes .../tests/strings/substr_compare.phpt | 2 +- .../tests/strings/substr_count_basic.phpt | 4 +- ext/standard/tests/strings/wordwrap.phpt | 2 +- .../tests/strings/wordwrap_error.phpt | 2 +- 26 files changed, 55 insertions(+), 59 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index 334e518d28ab2..6b5be7290e814 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -292,7 +292,7 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) / } } else if ((size_t)start > ZSTR_LEN(s11)) { /* Convert to Exception ? - zend_throw_exception(zend_ce_error_exception, "Offset not contained in string", E_ERROR); + zend_throw_error(NULL, "Offset not contained in string"); return; */ RETURN_FALSE; @@ -687,7 +687,7 @@ PHP_FUNCTION(nl_langinfo) break; default: /* TODO Convert to ErrorException - * zend_throw_exception(zend_ce_error_exception, "", E_ERROR); + * zend_throw_error(NULL, ""); */ php_error_docref(NULL, E_WARNING, "Item '" ZEND_LONG_FMT "' is not valid", item); RETURN_FALSE; @@ -941,12 +941,12 @@ PHP_FUNCTION(wordwrap) } if (breakchar_len == 0) { - zend_throw_exception(zend_ce_error_exception, "Break string cannot be empty", E_ERROR); + zend_throw_error(NULL, "Break string cannot be empty"); return; } if (linelength == 0 && docut) { - zend_throw_exception(zend_ce_error_exception, "Can't force cut when width is zero", E_ERROR); + zend_throw_error(NULL, "Can't force cut when width is zero"); return; } @@ -1153,7 +1153,7 @@ PHP_FUNCTION(explode) ZEND_PARSE_PARAMETERS_END(); if (ZSTR_LEN(delim) == 0) { - zend_throw_exception(zend_ce_error_exception, "Empty delimiter", E_ERROR); + zend_throw_error(NULL, "Empty delimiter"); return; } @@ -1652,7 +1652,7 @@ PHP_FUNCTION(dirname) ZSTR_LEN(ret) = zend_dirname(ZSTR_VAL(ret), str_len); #endif } else if (levels < 1) { - zend_throw_exception(zend_ce_error_exception, "Invalid argument, levels must be >= 1", E_ERROR); + zend_throw_error(NULL, "Invalid argument, levels must be >= 1"); zend_string_efree(ret); return; } else { @@ -1821,7 +1821,7 @@ PHP_FUNCTION(stristr) ZEND_PARSE_PARAMETERS_END(); if (!ZSTR_LEN(needle)) { - zend_throw_exception(zend_ce_error_exception, "Empty needle", E_ERROR); + zend_throw_error(NULL, "Empty needle"); return; } @@ -1862,7 +1862,7 @@ PHP_FUNCTION(strstr) ZEND_PARSE_PARAMETERS_END(); if (!ZSTR_LEN(needle)) { - zend_throw_exception(zend_ce_error_exception, "Empty needle", E_ERROR); + zend_throw_error(NULL, "Empty needle"); return; } @@ -1908,7 +1908,7 @@ PHP_FUNCTION(strpos) } if (!ZSTR_LEN(needle)) { - zend_throw_exception(zend_ce_error_exception, "Empty needle", E_ERROR); + zend_throw_error(NULL, "Empty needle"); return; } @@ -2202,7 +2202,7 @@ PHP_FUNCTION(chunk_split) ZEND_PARSE_PARAMETERS_END(); if (chunklen <= 0) { - zend_throw_exception(zend_ce_error_exception, "Chunk length should be greater than zero", E_ERROR); + zend_throw_error(NULL, "Chunk length should be greater than zero"); return; } @@ -5375,7 +5375,7 @@ PHP_FUNCTION(str_repeat) ZEND_PARSE_PARAMETERS_END(); if (mult < 0) { - zend_throw_exception(zend_ce_error_exception, "Second argument has to be greater than or equal to 0", E_ERROR); + zend_throw_error(NULL, "Second argument has to be greater than or equal to 0"); return; } @@ -5433,7 +5433,7 @@ PHP_FUNCTION(count_chars) ZEND_PARSE_PARAMETERS_END(); if (mymode < 0 || mymode > 4) { - zend_throw_exception(zend_ce_error_exception, "Unknown mode", E_ERROR); + zend_throw_error(NULL, "Unknown mode"); return; } @@ -5622,7 +5622,7 @@ PHP_FUNCTION(substr_count) ZEND_PARSE_PARAMETERS_END(); if (needle_len == 0) { - zend_throw_exception(zend_ce_error_exception, "Empty substring", E_ERROR); + zend_throw_error(NULL, "Empty substring"); return; } @@ -5700,19 +5700,19 @@ PHP_FUNCTION(str_pad) } if (pad_str_len == 0) { - zend_throw_exception(zend_ce_error_exception, "Padding string cannot be empty", E_ERROR); + zend_throw_error(NULL, "Padding string cannot be empty"); return; } if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH) { - zend_throw_exception(zend_ce_error_exception, - "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH", E_ERROR); + zend_throw_error(NULL, + "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH"); return; } num_pad_chars = pad_length - ZSTR_LEN(input); if (num_pad_chars >= INT_MAX) { - zend_throw_exception(zend_ce_error_exception, "Padding length is too long", E_ERROR); + zend_throw_error(NULL, "Padding length is too long"); return; } @@ -5972,7 +5972,7 @@ PHP_FUNCTION(str_word_count) break; default: /* Not sure how to proceed here - zend_throw_exception(zend_ce_error_exception, "Padding string cannot be empty", E_ERROR); + zend_throw_error(NULL, "Invalid format value " ZEND_LONG_FMT, type); return; */ php_error_docref(NULL, E_WARNING, "Invalid format value " ZEND_LONG_FMT, type); @@ -6092,7 +6092,7 @@ PHP_FUNCTION(str_split) ZEND_PARSE_PARAMETERS_END(); if (split_length <= 0) { - zend_throw_exception(zend_ce_error_exception, "The length of each segment must be greater than zero", E_ERROR); + zend_throw_error(NULL, "The length of each segment must be greater than zero"); return; } @@ -6132,7 +6132,7 @@ PHP_FUNCTION(strpbrk) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); if (!ZSTR_LEN(char_list)) { - zend_throw_exception(zend_ce_error_exception, "The character list cannot be empty", E_ERROR); + zend_throw_error(NULL, "The character list cannot be empty"); return; } @@ -6171,7 +6171,7 @@ PHP_FUNCTION(substr_compare) if (len == 0) { RETURN_LONG(0L); } else { - zend_throw_exception(zend_ce_error_exception, "The length must be greater than or equal to zero", E_ERROR); + zend_throw_error(NULL, "The length must be greater than or equal to zero"); return; } } diff --git a/ext/standard/tests/strings/bug33605.phpt b/ext/standard/tests/strings/bug33605.phpt index 4425f8f42c7f8..b3cb2ece957cb 100644 --- a/ext/standard/tests/strings/bug33605.phpt +++ b/ext/standard/tests/strings/bug33605.phpt @@ -4,7 +4,7 @@ Bug #33605 (substr_compare crashes) getMessage(); } diff --git a/ext/standard/tests/strings/bug63943.phpt b/ext/standard/tests/strings/bug63943.phpt index b3fb916360ba7..eee86808ca094 100644 --- a/ext/standard/tests/strings/bug63943.phpt +++ b/ext/standard/tests/strings/bug63943.phpt @@ -4,7 +4,7 @@ Bug #63943 (Bad warning text from strpos() on empty needle) getMessage(); } ?> diff --git a/ext/standard/tests/strings/chunk_split_variation5.phpt b/ext/standard/tests/strings/chunk_split_variation5.phpt index c4a3a33e7000588d3b9b8c2c437a48ee1d623ff5..bea49d24b48923832a447ba07d197f477c4f7d6f 100644 GIT binary patch delta 12 UcmdlYxLR<-1D4G%Sxz$p03`kega7~l delta 22 ecmZ22xJ7Wo0~Su#isaOSlFagetMessage(), "\n"; - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } } diff --git a/ext/standard/tests/strings/dirname_error.phpt b/ext/standard/tests/strings/dirname_error.phpt index 951fd9954b816..daf4e2cb0aa88 100644 --- a/ext/standard/tests/strings/dirname_error.phpt +++ b/ext/standard/tests/strings/dirname_error.phpt @@ -10,7 +10,7 @@ echo "*** Testing error conditions ***\n"; // Bad arg try { dirname("/var/tmp/bar.gz", 0); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } diff --git a/ext/standard/tests/strings/dirname_multi.phpt b/ext/standard/tests/strings/dirname_multi.phpt index d9fd15ddbab18..f95bf16d2a39c 100644 --- a/ext/standard/tests/strings/dirname_multi.phpt +++ b/ext/standard/tests/strings/dirname_multi.phpt @@ -13,7 +13,7 @@ if((substr(PHP_OS, 0, 3) == "WIN")) for ($i=0 ; $i<5 ; $i++) { try { var_dump(dirname("/foo/bar/baz", $i)); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } } diff --git a/ext/standard/tests/strings/dirname_multi_win.phpt b/ext/standard/tests/strings/dirname_multi_win.phpt index 636196492693d..ccfef1739ba6a 100644 --- a/ext/standard/tests/strings/dirname_multi_win.phpt +++ b/ext/standard/tests/strings/dirname_multi_win.phpt @@ -14,7 +14,7 @@ if((substr(PHP_OS, 0, 3) != "WIN")) for ($i=0 ; $i<5 ; $i++) { try { var_dump(dirname("/foo/bar/baz", $i)); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } } diff --git a/ext/standard/tests/strings/explode.phpt b/ext/standard/tests/strings/explode.phpt index 5bede0f1fa5d3..8fa3b62079264 100644 --- a/ext/standard/tests/strings/explode.phpt +++ b/ext/standard/tests/strings/explode.phpt @@ -14,17 +14,17 @@ echo "\n"; try { var_dump(explode("", "")); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } try { var_dump(explode("", NULL)); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } try { var_dump(explode(NULL, "")); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } @@ -33,7 +33,7 @@ var_dump(explode("a", "a")); var_dump(explode("a", NULL)); try { var_dump(explode(NULL, "a")); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } var_dump(explode("abc", "acb")); diff --git a/ext/standard/tests/strings/explode1.phpt b/ext/standard/tests/strings/explode1.phpt index 826f2355670f6..4d692e49e8041 100644 --- a/ext/standard/tests/strings/explode1.phpt +++ b/ext/standard/tests/strings/explode1.phpt @@ -36,22 +36,22 @@ foreach($delimiters as $delimiter) { try { var_dump( explode($delimiter, $string, -1) ); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } try { var_dump( explode($delimiter, $string, 0) ); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } try { var_dump( explode($delimiter, $string, 1) ); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } try { var_dump( explode($delimiter, $string, 2) ); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } $counter++; diff --git a/ext/standard/tests/strings/str_pad.phpt b/ext/standard/tests/strings/str_pad.phpt index fe1b111f20a74..a4f60bfa6ae27 100644 --- a/ext/standard/tests/strings/str_pad.phpt +++ b/ext/standard/tests/strings/str_pad.phpt @@ -67,13 +67,13 @@ echo "\n--- padding string as null ---\n"; try { str_pad($input_string, 12, NULL); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } try { str_pad($input_string, 12, ""); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } @@ -81,7 +81,7 @@ try { try { str_pad($input_string, $pad_length, "+", 15); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } diff --git a/ext/standard/tests/strings/str_repeat.phpt b/ext/standard/tests/strings/str_repeat.phpt index b73e58175a425d0aca61fe8f5ec41537b50af252..6e5f0cf68e618ec40a8e0db1fabfba3406d77b3f 100644 GIT binary patch delta 12 Tcmew>{zZI4IrHWQ=2{K_CYc2V delta 22 dcmew&{#SfMIWwngMRICENoIcD=5pp*4ghQb2($nI diff --git a/ext/standard/tests/strings/str_split_variation6.phpt b/ext/standard/tests/strings/str_split_variation6.phpt index 4ddf3a48ac97e..111eb11858aa4 100644 --- a/ext/standard/tests/strings/str_split_variation6.phpt +++ b/ext/standard/tests/strings/str_split_variation6.phpt @@ -39,7 +39,7 @@ for($count = 0; $count < count($values); $count++) { try { var_dump( str_split($str, $values[$count]) ); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } } diff --git a/ext/standard/tests/strings/str_split_variation6_64bit.phpt b/ext/standard/tests/strings/str_split_variation6_64bit.phpt index 79beb36427f59..e6893e9263ea5 100644 --- a/ext/standard/tests/strings/str_split_variation6_64bit.phpt +++ b/ext/standard/tests/strings/str_split_variation6_64bit.phpt @@ -39,7 +39,7 @@ for($count = 0; $count < count($values); $count++) { echo "-- Iteration ".($count + 1)." --\n"; try { var_dump( str_split($str, $values[$count]) ); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } } diff --git a/ext/standard/tests/strings/str_split_variation7.phpt b/ext/standard/tests/strings/str_split_variation7.phpt index 84f9deadef815..a810dd7ecb4d0 100644 --- a/ext/standard/tests/strings/str_split_variation7.phpt +++ b/ext/standard/tests/strings/str_split_variation7.phpt @@ -41,7 +41,7 @@ for($count = 0; $count < count($values); $count++) { try { var_dump( str_split($str, $values[$count]) ); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } } diff --git a/ext/standard/tests/strings/str_split_variation7_64bit.phpt b/ext/standard/tests/strings/str_split_variation7_64bit.phpt index 9c792dfd86f97..1a1980028a214 100644 --- a/ext/standard/tests/strings/str_split_variation7_64bit.phpt +++ b/ext/standard/tests/strings/str_split_variation7_64bit.phpt @@ -41,7 +41,7 @@ for($count = 0; $count < count($values); $count++) { echo "-- Iteration ".($count + 1)." --\n"; try { var_dump( str_split($str, $values[$count]) ); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } } diff --git a/ext/standard/tests/strings/stristr.phpt b/ext/standard/tests/strings/stristr.phpt index fd11e9bdce50f..ce06c00bdad17 100644 --- a/ext/standard/tests/strings/stristr.phpt +++ b/ext/standard/tests/strings/stristr.phpt @@ -11,19 +11,19 @@ stristr() function try { var_dump( stristr("", "") ); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } try { var_dump( stristr("a", "") ); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } try { var_dump( stristr("", "a") ); - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } var_dump(md5(stristr("\\\\a\\", "\\a"))); diff --git a/ext/standard/tests/strings/stristr_error.phpt b/ext/standard/tests/strings/stristr_error.phpt index cbfc1ddd99c9f..03c2538a55aee 100644 --- a/ext/standard/tests/strings/stristr_error.phpt +++ b/ext/standard/tests/strings/stristr_error.phpt @@ -11,14 +11,14 @@ echo "*** Testing stristr() : error conditions ***\n"; echo "\n-- Testing stristr() function with empty haystack --\n"; try { stristr(NULL, ""); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } echo "\n-- Testing stristr() function with empty needle --\n"; try { stristr("Hello World", ""); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } diff --git a/ext/standard/tests/strings/stristr_variation2.phpt b/ext/standard/tests/strings/stristr_variation2.phpt index af9148f9e3929..94f4adcd398d2 100644 --- a/ext/standard/tests/strings/stristr_variation2.phpt +++ b/ext/standard/tests/strings/stristr_variation2.phpt @@ -76,7 +76,7 @@ foreach($inputs as $input) { var_dump( stristr("Hello World", $input) ); } catch (TypeError $e) { echo $e->getMessage(), "\n"; - } catch (\ErrorException $e) { + } catch (\Error $e) { echo $e->getMessage() . "\n"; } $count ++; diff --git a/ext/standard/tests/strings/strpbrk_error.phpt b/ext/standard/tests/strings/strpbrk_error.phpt index f55a3967aad44..c81f809a1c423 100644 --- a/ext/standard/tests/strings/strpbrk_error.phpt +++ b/ext/standard/tests/strings/strpbrk_error.phpt @@ -8,23 +8,19 @@ Test strpbrk() function : error conditions * Alias to functions: */ -echo "*** Testing strpbrk() : error conditions ***\n"; - $haystack = 'This is a Simple text.'; -echo "\n-- Testing strpbrk() function with empty second argument --\n"; +echo "-- Testing strpbrk() function with empty second argument --\n"; try { strpbrk($haystack, ''); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } ?> ===DONE=== --EXPECTF-- -*** Testing strpbrk() : error conditions *** - -- Testing strpbrk() function with empty second argument -- The character list cannot be empty ===DONE=== diff --git a/ext/standard/tests/strings/strpos.phpt b/ext/standard/tests/strings/strpos.phpt index 8983c33f943939f0c609c4841c3c16767cddc382..b312bf30d315c987b2f5b58888aa9b6e4fe7a189 100644 GIT binary patch delta 188 zcmZ4OImu(g1g6OwM0F+`Fw0C9;A5Hmlt~QAHv`d|XEWrP9+OS^3{gaMHc#T~U_lXbpL{@!Wpb)8s*@n1r-UU@ s)aq>J7tvuv6G|5qLKOn(^+8bt5)qu7B5sE!`chm5MMP(_p~ORO0285fYybcN diff --git a/ext/standard/tests/strings/strstr.phpt b/ext/standard/tests/strings/strstr.phpt index 4c2ead3ce5bd16fa9ad931f638c57c46447c2038..0e1d787637adc9057b0fbd7ee2b6f89d019a1262 100644 GIT binary patch delta 153 zcmX@_bHaPWJf_Kv+&Ysla7s^p$0QABM>2!in^!XbVcNWo?JZ1|B|-(4ES!Ce%V;wr zHx~<7z=0p4$bnyR@_Bx7pqTk)H33CNkmTkXK|wGBXd&n1(?V`w9TzwiC#MUGffZ~L Ho+|_Zy(lhk delta 307 zcmX@%ecoroJSI-pisaOSlFa78#vgetMessage() . "\n"; } var_dump(substr_compare("abcde", "abc", -1, NULL, -5) > 0); diff --git a/ext/standard/tests/strings/substr_count_basic.phpt b/ext/standard/tests/strings/substr_count_basic.phpt index d52d6a3bbde58..385689e697050 100644 --- a/ext/standard/tests/strings/substr_count_basic.phpt +++ b/ext/standard/tests/strings/substr_count_basic.phpt @@ -6,12 +6,12 @@ Test substr_count() function (basic) echo "***Testing basic operations ***\n"; try { substr_count("", ""); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } try { substr_count("a", ""); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } var_dump(substr_count("", "a")); diff --git a/ext/standard/tests/strings/wordwrap.phpt b/ext/standard/tests/strings/wordwrap.phpt index 23958b17ff3f5..8c2b08f0462e7 100644 --- a/ext/standard/tests/strings/wordwrap.phpt +++ b/ext/standard/tests/strings/wordwrap.phpt @@ -35,7 +35,7 @@ echo "\n"; try { wordwrap(chr(0), 0, ""); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } --EXPECT-- diff --git a/ext/standard/tests/strings/wordwrap_error.phpt b/ext/standard/tests/strings/wordwrap_error.phpt index fe79daecfac62..f0fa80f63d440 100644 --- a/ext/standard/tests/strings/wordwrap_error.phpt +++ b/ext/standard/tests/strings/wordwrap_error.phpt @@ -29,7 +29,7 @@ $cut = true; try { wordwrap($str, $width, $break, $cut); -} catch (\ErrorException $e) { +} catch (\Error $e) { echo $e->getMessage() . "\n"; } From 18156c7c3513a93d5709fc63f734335adf56e92d Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sun, 18 Aug 2019 13:53:38 +0200 Subject: [PATCH 05/12] Promote warning to Error in str_word_count() --- ext/standard/string.c | 6 +-- .../tests/strings/str_word_count.phpt | 54 ++++++++++++------- .../tests/strings/str_word_count1.phpt | 30 +++++++---- 3 files changed, 54 insertions(+), 36 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index 6b5be7290e814..a39a4fa5d3aaa 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -5930,7 +5930,7 @@ PHP_FUNCTION(str_shuffle) } /* }}} */ -/* {{{ proto array|int|null|false str_word_count(string str, [int format [, string charlist]]) +/* {{{ proto array|int str_word_count(string str, [int format [, string charlist]]) Counts the number of words inside a string. If format of 1 is specified, then the function will return an array containing all the words found inside the string. If format of 2 is specified, then the function @@ -5971,12 +5971,8 @@ PHP_FUNCTION(str_word_count) /* nothing to be done */ break; default: - /* Not sure how to proceed here zend_throw_error(NULL, "Invalid format value " ZEND_LONG_FMT, type); return; - */ - php_error_docref(NULL, E_WARNING, "Invalid format value " ZEND_LONG_FMT, type); - RETURN_FALSE; } if (char_list) { diff --git a/ext/standard/tests/strings/str_word_count.phpt b/ext/standard/tests/strings/str_word_count.phpt index e8fa12aca6d7c..375f26dee0340 100644 --- a/ext/standard/tests/strings/str_word_count.phpt +++ b/ext/standard/tests/strings/str_word_count.phpt @@ -2,17 +2,37 @@ str_word_count() --FILE-- getMessage() . "\n"; +} + +try { + var_dump(str_word_count($str, 123)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(str_word_count($str, -1)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(str_word_count($str, 999999999)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + var_dump($str); $str2 = "F0o B4r 1s bar foo"; @@ -34,9 +54,10 @@ var_dump(str_word_count("'foo'", 2, "'")); var_dump(str_word_count("-foo-", 2)); var_dump(str_word_count("-foo-", 2, "-")); -echo "Done\n"; ?> ---EXPECTF-- + +DONE +--EXPECT-- array(6) { [0]=> string(5) "Hello" @@ -66,18 +87,10 @@ array(6) { string(5) "today" } int(6) - -Warning: str_word_count(): Invalid format value 3 in %s on line %d -bool(false) - -Warning: str_word_count(): Invalid format value 123 in %s on line %d -bool(false) - -Warning: str_word_count(): Invalid format value -1 in %s on line %d -bool(false) - -Warning: str_word_count(): Invalid format value 999999999 in %s on line %d -bool(false) +Invalid format value 3 +Invalid format value 123 +Invalid format value -1 +Invalid format value 999999999 string(55) "Hello friend, you're looking good today!" int(5) @@ -214,4 +227,5 @@ array(1) { [0]=> string(5) "-foo-" } -Done + +DONE diff --git a/ext/standard/tests/strings/str_word_count1.phpt b/ext/standard/tests/strings/str_word_count1.phpt index e942a17385886..18652699e232b 100644 --- a/ext/standard/tests/strings/str_word_count1.phpt +++ b/ext/standard/tests/strings/str_word_count1.phpt @@ -4,23 +4,31 @@ str_word_count() and invalid arguments getMessage() . "\n"; +} + +try { + var_dump(str_word_count("", -1, $a)); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +var_dump($a); ?> + +DONE --EXPECTF-- int(0) - -Warning: str_word_count(): Invalid format value -1 in %s on line %d -bool(false) +Invalid format value -1 Notice: Undefined variable: a in %s on line %d - -Warning: str_word_count(): Invalid format value -1 in %s on line %d -bool(false) +Invalid format value -1 Notice: Undefined variable: a in %s on line %d NULL -Done + +DONE From 6aaa89923b30aba53fec8704d4164de48a2a8efe Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sun, 18 Aug 2019 15:10:44 +0200 Subject: [PATCH 06/12] Possible regression test fix for bug73646 --- ext/mbstring/tests/bug73646.phpt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/ext/mbstring/tests/bug73646.phpt b/ext/mbstring/tests/bug73646.phpt index f2adec521d934..cd4248e3d5388 100644 --- a/ext/mbstring/tests/bug73646.phpt +++ b/ext/mbstring/tests/bug73646.phpt @@ -7,15 +7,7 @@ if (!function_exists('mb_ereg')) die('skip mbregex support not available'); ?> --FILE-- getMessage() . "\n"; -} - -var_dump(mb_ereg_search_init($v1)); +var_dump(mb_ereg_search_init(NULL)); ?> --EXPECT-- Second argument has to be greater than or equal to 0 From 7f93c77c832509b66c1d4e5b412e79c30d8d3c11 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sun, 18 Aug 2019 15:28:13 +0200 Subject: [PATCH 07/12] Fix opcache regression test for bug70207 --- ext/opcache/tests/bug70207.phpt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/opcache/tests/bug70207.phpt b/ext/opcache/tests/bug70207.phpt index ff0d4432da53c..2b6e48a2d4b23 100644 --- a/ext/opcache/tests/bug70207.phpt +++ b/ext/opcache/tests/bug70207.phpt @@ -15,8 +15,7 @@ function bar() { function foo() { try { return bar(); } finally { - try { @str_repeat("foo", -10); } - catch (\ErrorException $e) {} + @fopen("non-existent", 'r'); } } From 099fcdf6222b55795d6d1f1a158807af73525181 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sun, 18 Aug 2019 16:52:57 +0200 Subject: [PATCH 08/12] Fix test expected output --- ext/mbstring/tests/bug73646.phpt | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/mbstring/tests/bug73646.phpt b/ext/mbstring/tests/bug73646.phpt index cd4248e3d5388..ea57017f1167c 100644 --- a/ext/mbstring/tests/bug73646.phpt +++ b/ext/mbstring/tests/bug73646.phpt @@ -10,5 +10,4 @@ if (!function_exists('mb_ereg')) die('skip mbregex support not available'); var_dump(mb_ereg_search_init(NULL)); ?> --EXPECT-- -Second argument has to be greater than or equal to 0 bool(true) From 96017b8bbf35aacace41cff385c914085dfc8595 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 19 Aug 2019 01:40:10 +0200 Subject: [PATCH 09/12] Normalizing question annotating comments --- ext/standard/string.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index a39a4fa5d3aaa..c1081c8947f82 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -291,10 +291,6 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) / start = 0; } } else if ((size_t)start > ZSTR_LEN(s11)) { - /* Convert to Exception ? - zend_throw_error(NULL, "Offset not contained in string"); - return; - */ RETURN_FALSE; } @@ -686,11 +682,8 @@ PHP_FUNCTION(nl_langinfo) #endif break; default: - /* TODO Convert to ErrorException - * zend_throw_error(NULL, ""); - */ - php_error_docref(NULL, E_WARNING, "Item '" ZEND_LONG_FMT "' is not valid", item); - RETURN_FALSE; + zend_throw_error(NULL, E_WARNING, "Item '" ZEND_LONG_FMT "' is not valid", item); + return; } /* }}} */ @@ -725,7 +718,6 @@ PHP_FUNCTION(strcoll) * it needs to be incrementing. * Returns: FAILURE/SUCCESS whether the input was correct (i.e. no range errors) */ -/* TODO (maybe) convert docref errors into ErrorException? */ static inline int php_charmask(const unsigned char *input, size_t len, char *mask) { const unsigned char *end; @@ -743,21 +735,25 @@ static inline int php_charmask(const unsigned char *input, size_t len, char *mas /* Error, try to be as helpful as possible: (a range ending/starting with '.' won't be captured here) */ if (end-len >= input) { /* there was no 'left' char */ + /* TODO Check if Candidate to convert to Exception */ php_error_docref(NULL, E_WARNING, "Invalid '..'-range, no character to the left of '..'"); result = FAILURE; continue; } if (input+2 >= end) { /* there is no 'right' char */ + /* TODO Check if Candidate to convert to Exception */ php_error_docref(NULL, E_WARNING, "Invalid '..'-range, no character to the right of '..'"); result = FAILURE; continue; } if (input[-1] > input[2]) { /* wrong order */ + /* TODO Check if Candidate to convert to Exception */ php_error_docref(NULL, E_WARNING, "Invalid '..'-range, '..'-range needs to be incrementing"); result = FAILURE; continue; } /* FIXME: better error (a..b..c is the only left possibility?) */ + /* TODO Check if Candidate to convert to Exception */ php_error_docref(NULL, E_WARNING, "Invalid '..'-range"); result = FAILURE; continue; @@ -2358,13 +2354,13 @@ PHP_FUNCTION(substr_replace) (argc == 3 && Z_TYPE_P(from) == IS_ARRAY) || (argc == 4 && Z_TYPE_P(from) != Z_TYPE_P(len)) ) { - /* TODO can convert to TypeError ? */ + /* TODO Check if Candidate to convert to TypeError ? */ php_error_docref(NULL, E_WARNING, "'start' and 'length' should be of same type - numerical or array "); RETURN_STR_COPY(Z_STR_P(str)); } if (argc == 4 && Z_TYPE_P(from) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(from)) != zend_hash_num_elements(Z_ARRVAL_P(len))) { - /* TODO can convert to Exception ? */ + /* TODO Check if Candidate to convert to Exception */ php_error_docref(NULL, E_WARNING, "'start' and 'length' should have the same number of elements"); RETURN_STR_COPY(Z_STR_P(str)); } @@ -2434,7 +2430,7 @@ PHP_FUNCTION(substr_replace) zend_tmp_string_release(tmp_repl_str); RETURN_NEW_STR(result); } else { - /* TODO can convert to Exception ? */ + /* TODO Check if Candidate to convert to Exception */ php_error_docref(NULL, E_WARNING, "Functionality of 'start' and 'length' as arrays is not implemented"); RETURN_STR_COPY(Z_STR_P(str)); } @@ -5644,7 +5640,7 @@ PHP_FUNCTION(substr_count) length += (haystack_len - offset); } if (length < 0 || ((size_t)length > (haystack_len - offset))) { - /* Convert to Exception ? */ + /* TODO Check if Candidate to convert to Exception */ php_error_docref(NULL, E_WARNING, "Invalid length value"); RETURN_FALSE; } @@ -6178,7 +6174,7 @@ PHP_FUNCTION(substr_compare) } if ((size_t)offset > ZSTR_LEN(s1)) { - /* Candidate to convert to Exception ? */ + /* TODO Check if Candidate to convert to Exception */ php_error_docref(NULL, E_WARNING, "The start position cannot exceed initial string length"); RETURN_FALSE; } From 69ed5b63a7108ef5e640aa660810f9dc72ecc4ea Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 19 Aug 2019 01:52:45 +0200 Subject: [PATCH 10/12] Revert changes to strpos and strstr family as covered in another PR --- ext/standard/string.c | 12 +++---- ext/standard/tests/strings/bug63943.phpt | 8 ++--- ext/standard/tests/strings/stristr.phpt | 31 ++++-------------- ext/standard/tests/strings/stristr_error.phpt | 20 +++++------ .../tests/strings/stristr_variation2.phpt | 28 +++++++++++----- ext/standard/tests/strings/strpos.phpt | Bin 9234 -> 9009 bytes ext/standard/tests/strings/strstr.phpt | Bin 9672 -> 9649 bytes 7 files changed, 41 insertions(+), 58 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index c1081c8947f82..aa066c6621574 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1817,8 +1817,8 @@ PHP_FUNCTION(stristr) ZEND_PARSE_PARAMETERS_END(); if (!ZSTR_LEN(needle)) { - zend_throw_error(NULL, "Empty needle"); - return; + php_error_docref(NULL, E_WARNING, "Empty needle"); + RETURN_FALSE; } haystack_dup = estrndup(ZSTR_VAL(haystack), ZSTR_LEN(haystack)); @@ -1858,8 +1858,8 @@ PHP_FUNCTION(strstr) ZEND_PARSE_PARAMETERS_END(); if (!ZSTR_LEN(needle)) { - zend_throw_error(NULL, "Empty needle"); - return; + php_error_docref(NULL, E_WARNING, "Empty needle"); + RETURN_FALSE; } found = php_memnstr(ZSTR_VAL(haystack), ZSTR_VAL(needle), ZSTR_LEN(needle), ZSTR_VAL(haystack) + ZSTR_LEN(haystack)); @@ -1904,8 +1904,8 @@ PHP_FUNCTION(strpos) } if (!ZSTR_LEN(needle)) { - zend_throw_error(NULL, "Empty needle"); - return; + php_error_docref(NULL, E_WARNING, "Empty needle"); + RETURN_FALSE; } found = (char*)php_memnstr(ZSTR_VAL(haystack) + offset, diff --git a/ext/standard/tests/strings/bug63943.phpt b/ext/standard/tests/strings/bug63943.phpt index eee86808ca094..6018879b24a6d 100644 --- a/ext/standard/tests/strings/bug63943.phpt +++ b/ext/standard/tests/strings/bug63943.phpt @@ -2,11 +2,7 @@ Bug #63943 (Bad warning text from strpos() on empty needle) --FILE-- getMessage(); -} +strpos("lllllll", ''); ?> --EXPECTF-- -Empty needle +Warning: strpos(): Empty needle in %sbug63943.php on line %d diff --git a/ext/standard/tests/strings/stristr.phpt b/ext/standard/tests/strings/stristr.phpt index ce06c00bdad17..92cfa09eb1e17 100644 --- a/ext/standard/tests/strings/stristr.phpt +++ b/ext/standard/tests/strings/stristr.phpt @@ -8,29 +8,12 @@ stristr() function var_dump(stristr("tEsT sTrInG", "t S")); var_dump(stristr("tEsT sTrInG", "g")); var_dump(md5(stristr("te".chr(0)."st", chr(0)))); - - try { - var_dump( stristr("", "") ); - } catch (\Error $e) { - echo $e->getMessage() . "\n"; - } - - try { - var_dump( stristr("a", "") ); - } catch (\Error $e) { - echo $e->getMessage() . "\n"; - } - - try { - var_dump( stristr("", "a") ); - } catch (\Error $e) { - echo $e->getMessage() . "\n"; - } - var_dump(md5(stristr("\\\\a\\", "\\a"))); + var_dump(@stristr("", "")); + var_dump(@stristr("a", "")); + var_dump(@stristr("", "a")); + var_dump(md5(@stristr("\\\\a\\", "\\a"))); var_dump(stristr("tEsT sTrInG", " ")); ?> - -DONE --EXPECTF-- string(11) "tEsT sTrInG" string(6) "sTrInG" @@ -38,10 +21,8 @@ string(6) "sTrInG" string(8) "T sTrInG" string(1) "G" string(32) "7272696018bdeb2c9a3f8d01fc2a9273" -Empty needle -Empty needle +bool(false) +bool(false) bool(false) string(32) "6ec19f52f0766c463f3bb240f4396913" string(7) " sTrInG" - -DONE diff --git a/ext/standard/tests/strings/stristr_error.phpt b/ext/standard/tests/strings/stristr_error.phpt index 03c2538a55aee..a7b683d3b8681 100644 --- a/ext/standard/tests/strings/stristr_error.phpt +++ b/ext/standard/tests/strings/stristr_error.phpt @@ -9,18 +9,10 @@ Test stristr() function : error conditions echo "*** Testing stristr() : error conditions ***\n"; echo "\n-- Testing stristr() function with empty haystack --\n"; -try { - stristr(NULL, ""); -} catch (\Error $e) { - echo $e->getMessage() . "\n"; -} +var_dump( stristr(NULL, "") ); echo "\n-- Testing stristr() function with empty needle --\n"; -try { - stristr("Hello World", ""); -} catch (\Error $e) { - echo $e->getMessage() . "\n"; -} +var_dump( stristr("Hello World", "") ); ?> ===DONE=== @@ -28,8 +20,12 @@ try { *** Testing stristr() : error conditions *** -- Testing stristr() function with empty haystack -- -Empty needle + +Warning: stristr(): Empty needle in %s on line %d +bool(false) -- Testing stristr() function with empty needle -- -Empty needle + +Warning: stristr(): Empty needle in %s on line %d +bool(false) ===DONE=== diff --git a/ext/standard/tests/strings/stristr_variation2.phpt b/ext/standard/tests/strings/stristr_variation2.phpt index 94f4adcd398d2..fd842d1106441 100644 --- a/ext/standard/tests/strings/stristr_variation2.phpt +++ b/ext/standard/tests/strings/stristr_variation2.phpt @@ -76,9 +76,7 @@ foreach($inputs as $input) { var_dump( stristr("Hello World", $input) ); } catch (TypeError $e) { echo $e->getMessage(), "\n"; - } catch (\Error $e) { - echo $e->getMessage() . "\n"; - } + } $count ++; } @@ -111,21 +109,33 @@ stristr() expects parameter 2 to be string, array given -- Iteration 11 -- bool(false) -- Iteration 12 -- -Empty needle + +Warning: stristr(): Empty needle in %s on line %d +bool(false) -- Iteration 13 -- bool(false) -- Iteration 14 -- -Empty needle + +Warning: stristr(): Empty needle in %s on line %d +bool(false) -- Iteration 15 -- -Empty needle + +Warning: stristr(): Empty needle in %s on line %d +bool(false) -- Iteration 16 -- -Empty needle + +Warning: stristr(): Empty needle in %s on line %d +bool(false) -- Iteration 17 -- bool(false) -- Iteration 18 -- stristr() expects parameter 2 to be string, resource given -- Iteration 19 -- -Empty needle + +Warning: stristr(): Empty needle in %s on line %d +bool(false) -- Iteration 20 -- -Empty needle + +Warning: stristr(): Empty needle in %s on line %d +bool(false) ===DONE=== diff --git a/ext/standard/tests/strings/strpos.phpt b/ext/standard/tests/strings/strpos.phpt index b312bf30d315c987b2f5b58888aa9b6e4fe7a189..4640b670f316314e6a8720da849fa7cb8c84bc38 100644 GIT binary patch delta 1273 zcmbVKO-~b16txwLeGJ8Zmyg2jR6++^ghC63fG*UqAcTz@gC7H(+KJOQb!HG<7;vk* z-XEX~6XQoBq<=uRtRykUl?icUbi>w-_+Hy-Dv*Y_czI{uJ@>xz&Ybex*7ePs&fG)U zxRYBgmJ)Eqw2YE&CPXm_q9}nhO^zwbEvvjJAL*?;JN?#)S=TVeJbwHba^rKC*ZG8C zS15!_(TkPQ_BN+WSt;ls;@Ch8Z@C9>&o_X#LoR&nj^U0wiZ6vTxbKFFk5~@;-O(2| z6l>L>AkHb8rYB)dH?*8MO>ny-%j@UtdZQo-F)TZLm=^%Ig$q^e?i4WZ@Z$Z>F1Gv5 z^5-qwn4d@45yp&1tdugxhg9l*BD>FT+{<8t(TuoWH75g^44VXK^aBf$t-N zy(-@#`wo=j{{CyllJyv`&eiz=22ZZLa zSdOQU97xTKqZcphx|YbxnyEKlXa#u=J(ovv}SrBI>QtGbB6B&g! zA7fg?G&zk`M-c3llA=nerxX+>8;D3vUdJlv1M(wo-@`)y>QC4xXA&0zxf&#M5V7sL!mvSh|BiS5MS&)hz^pn?fXfgxUOy0*Tx%m@E6yszs zE;(6{O+~3CrA2uPN*<{>Ir%yY<@rT9DZtnO8ePw222v%0P=h4-kV_F9@xt7SF1Y$dX}Si5G{`6_g^|27&{dQ=YVurxE6_4UUr1>36hT=_vO{e02EjFx z53`C){;ep2NL#9o)Cf1#$=)Ky6ebAO$umXFC^SQQ@&gfGC$fWxi_6}Q%f;W%b&_a< zq-$p;HX0szyh1YGy|3g+lp{y*Y5Zt_WC;Ji2|3I zW4H#h9AKN^u%;FkGb~O(3)#VxUvvsoTLaaBO=g{YdA0P3AMa6NKdBMVH! z(jeC$8;qIKrfNEx>@A)6BIFO80`>7z-np@Iw0+>vz12zI(Um@~{&*rO9^&eq;gk3- z`>;RV@k&l=A99q)f4Ba?_Wkcaes%VDKiTHJUJFM=D#<{*NJ={X5b!SI4JGBdzeCBu b9#@&W!mPNJ%g!FO_mHc%*ypSJ13`WR&w;jg delta 1519 zcmdn!eZqS~22&1KNl~RjHJ1VqlqD9$rh6V9V8%G{C0r# zbJb2hz$8BTthCJLv#kD1$N?q8A?J$QeEepk2Duf70+md%6A+tRz`;o+(<(VkEXnra z<~1D4n7NSy>?5~m05Gw}7~qY3g7JbHb`V4TLVbLwmX&sZ_{IO-;#3pu{cV;zY yH7G`)a5n#!5nw~nJ=sTj5~_f-ipFGSRYe^X6O;1ub2QQtbBa?nQ4EB5f(rm=a<=9G From 56fe9eb624ab63f318decc2f367568af8f332cc7 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 19 Aug 2019 01:56:06 +0200 Subject: [PATCH 11/12] Fix Windows specific test --- ext/standard/tests/strings/dirname_multi_win.phpt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ext/standard/tests/strings/dirname_multi_win.phpt b/ext/standard/tests/strings/dirname_multi_win.phpt index ccfef1739ba6a..9dc0c05c59732 100644 --- a/ext/standard/tests/strings/dirname_multi_win.phpt +++ b/ext/standard/tests/strings/dirname_multi_win.phpt @@ -13,14 +13,12 @@ if((substr(PHP_OS, 0, 3) != "WIN")) for ($i=0 ; $i<5 ; $i++) { try { - var_dump(dirname("/foo/bar/baz", $i)); + var_dump(dirname("/foo/bar/baz", $i)); } catch (\Error $e) { echo $e->getMessage() . "\n"; } } -for ($i=0 ; $i<5 ; $i++) { - var_dump(dirname("/foo/bar/baz", $i)); -} + var_dump(dirname("/foo/bar/baz", PHP_INT_MAX)); var_dump(dirname("g:/foo/bar/baz", PHP_INT_MAX)); var_dump(dirname("g:foo/bar/baz", PHP_INT_MAX)); From b449ff00155a9e75a39ba80eb434d43e8901c90b Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 19 Aug 2019 02:07:24 +0200 Subject: [PATCH 12/12] Fix compile --- ext/standard/string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index aa066c6621574..776ad0748fe40 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -682,7 +682,7 @@ PHP_FUNCTION(nl_langinfo) #endif break; default: - zend_throw_error(NULL, E_WARNING, "Item '" ZEND_LONG_FMT "' is not valid", item); + zend_throw_error(NULL, "Item '" ZEND_LONG_FMT "' is not valid", item); return; } /* }}} */