diff --git a/ext/mbstring/tests/bug73646.phpt b/ext/mbstring/tests/bug73646.phpt index 7ac824d69cb4d..ea57017f1167c 100644 --- a/ext/mbstring/tests/bug73646.phpt +++ b/ext/mbstring/tests/bug73646.phpt @@ -7,10 +7,7 @@ if (!function_exists('mb_ereg')) die('skip mbregex support not available'); ?> --FILE-- ---EXPECTF-- -Warning: str_repeat(): Second argument has to be greater than or equal to 0 in %sbug73646.php on line %d +--EXPECT-- bool(true) diff --git a/ext/opcache/tests/bug70207.phpt b/ext/opcache/tests/bug70207.phpt index 806ea7535b67e..2b6e48a2d4b23 100644 --- a/ext/opcache/tests/bug70207.phpt +++ b/ext/opcache/tests/bug70207.phpt @@ -14,7 +14,9 @@ function bar() { } function foo() { try { return bar(); } - finally { @str_repeat("foo", -10); } + finally { + @fopen("non-existent", 'r'); + } } var_dump(foo()); diff --git a/ext/standard/string.c b/ext/standard/string.c index c2f29baec7732..776ad0748fe40 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -324,7 +324,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 +332,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,8 +682,8 @@ PHP_FUNCTION(nl_langinfo) #endif break; default: - php_error_docref(NULL, E_WARNING, "Item '" ZEND_LONG_FMT "' is not valid", item); - RETURN_FALSE; + zend_throw_error(NULL, "Item '" ZEND_LONG_FMT "' is not valid", item); + return; } /* }}} */ @@ -735,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; @@ -907,7 +911,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 +937,13 @@ PHP_FUNCTION(wordwrap) } if (breakchar_len == 0) { - php_error_docref(NULL, E_WARNING, "Break string cannot be empty"); - RETURN_FALSE; + zend_throw_error(NULL, "Break string cannot be empty"); + return; } if (linelength == 0 && docut) { - php_error_docref(NULL, E_WARNING, "Can't force cut when width is zero"); - RETURN_FALSE; + zend_throw_error(NULL, "Can't force cut when width is zero"); + return; } /* Special case for a single-character break as it needs no @@ -1129,7 +1133,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 +1149,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_error(NULL, "Empty delimiter"); + return; } array_init(return_value); @@ -1619,7 +1623,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 +1648,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_error(NULL, "Invalid argument, levels must be >= 1"); zend_string_efree(ret); return; } else { @@ -2194,8 +2198,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_error(NULL, "Chunk length should be greater than zero"); + return; } if ((size_t)chunklen > ZSTR_LEN(str)) { @@ -2350,11 +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 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 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)); } @@ -2424,6 +2430,7 @@ PHP_FUNCTION(substr_replace) zend_tmp_string_release(tmp_repl_str); RETURN_NEW_STR(result); } else { + /* 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)); } @@ -3292,7 +3299,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 +3317,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 +3366,7 @@ PHP_FUNCTION(strtr) } } else { if (!try_convert_to_string(from)) { + zend_type_error("Cannot convert 'from' into string."); return; } @@ -5363,7 +5371,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_error(NULL, "Second argument has to be greater than or equal to 0"); return; } @@ -5401,7 +5409,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 +5429,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_error(NULL, "Unknown mode"); + return; } buf = (const unsigned char *) ZSTR_VAL(input); @@ -5610,8 +5618,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_error(NULL, "Empty substring"); + return; } p = haystack; @@ -5632,6 +5640,7 @@ PHP_FUNCTION(substr_count) length += (haystack_len - offset); } if (length < 0 || ((size_t)length > (haystack_len - offset))) { + /* TODO Check if Candidate to convert to Exception */ php_error_docref(NULL, E_WARNING, "Invalid length value"); RETURN_FALSE; } @@ -5687,18 +5696,19 @@ PHP_FUNCTION(str_pad) } if (pad_str_len == 0) { - php_error_docref(NULL, E_WARNING, "Padding string cannot be empty"); + zend_throw_error(NULL, "Padding string cannot be empty"); 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_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) { - php_error_docref(NULL, E_WARNING, "Padding length is too long"); + zend_throw_error(NULL, "Padding length is too long"); return; } @@ -5916,7 +5926,7 @@ PHP_FUNCTION(str_shuffle) } /* }}} */ -/* {{{ proto mixed 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 @@ -5957,8 +5967,8 @@ PHP_FUNCTION(str_word_count) /* nothing to be done */ break; default: - php_error_docref(NULL, E_WARNING, "Invalid format value " ZEND_LONG_FMT, type); - RETURN_FALSE; + zend_throw_error(NULL, "Invalid format value " ZEND_LONG_FMT, type); + return; } if (char_list) { @@ -6058,7 +6068,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 +6084,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_error(NULL, "The length of each segment must be greater than zero"); + return; } @@ -6114,8 +6124,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_error(NULL, "The character list cannot be empty"); + return; } for (haystack_ptr = ZSTR_VAL(haystack); haystack_ptr < (ZSTR_VAL(haystack) + ZSTR_LEN(haystack)); ++haystack_ptr) { @@ -6153,8 +6163,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_error(NULL, "The length must be greater than or equal to zero"); + return; } } @@ -6164,6 +6174,7 @@ PHP_FUNCTION(substr_compare) } if ((size_t)offset > ZSTR_LEN(s1)) { + /* TODO Check if 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..b3cb2ece957cb 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/chunk_split_variation5.phpt b/ext/standard/tests/strings/chunk_split_variation5.phpt index 8650f2cb92f80..bea49d24b4892 100644 Binary files a/ext/standard/tests/strings/chunk_split_variation5.phpt and b/ext/standard/tests/strings/chunk_split_variation5.phpt differ diff --git a/ext/standard/tests/strings/chunk_split_variation8.phpt b/ext/standard/tests/strings/chunk_split_variation8.phpt index 9804ee21e13f7..15c224962e103 100644 --- a/ext/standard/tests/strings/chunk_split_variation8.phpt +++ b/ext/standard/tests/strings/chunk_split_variation8.phpt @@ -50,6 +50,8 @@ for($count = 0; $count < count($values); $count++) { var_dump( chunk_split($heredoc_str, $values[$count], $ending) ); } catch (TypeError $e) { echo $e->getMessage(), "\n"; + } catch (\Error $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..daf4e2cb0aa88 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 (\Error $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..f95bf16d2a39c 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 (\Error $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/dirname_multi_win.phpt b/ext/standard/tests/strings/dirname_multi_win.phpt index 4fed5895e634f..9dc0c05c59732 100644 --- a/ext/standard/tests/strings/dirname_multi_win.phpt +++ b/ext/standard/tests/strings/dirname_multi_win.phpt @@ -10,17 +10,22 @@ 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++) { - var_dump(dirname("/foo/bar/baz", $i)); + try { + var_dump(dirname("/foo/bar/baz", $i)); + } catch (\Error $e) { + echo $e->getMessage() . "\n"; + } } + 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)); ?> 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) "\" diff --git a/ext/standard/tests/strings/explode.phpt b/ext/standard/tests/strings/explode.phpt index 84cdcb985fef6..8fa3b62079264 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 (\Error $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump(explode(NULL, "")); +} catch (\Error $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 (\Error $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..4d692e49e8041 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 (\Error $e) { + echo $e->getMessage() . "\n"; + } + try { + var_dump( explode($delimiter, $string, 0) ); + } catch (\Error $e) { + echo $e->getMessage() . "\n"; + } + try { + var_dump( explode($delimiter, $string, 1) ); + } catch (\Error $e) { + echo $e->getMessage() . "\n"; + } + try { + var_dump( explode($delimiter, $string, 2) ); + } catch (\Error $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 be4c9ed942869..a4f60bfa6ae27 100644 Binary files a/ext/standard/tests/strings/str_pad.phpt and b/ext/standard/tests/strings/str_pad.phpt differ 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 766bea1f9c32d..6e5f0cf68e618 100644 Binary files a/ext/standard/tests/strings/str_repeat.phpt and b/ext/standard/tests/strings/str_repeat.phpt differ diff --git a/ext/standard/tests/strings/str_repeat_variation1.phpt b/ext/standard/tests/strings/str_repeat_variation1.phpt new file mode 100644 index 0000000000000..4740f7c5b8439 --- /dev/null +++ b/ext/standard/tests/strings/str_repeat_variation1.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test str_repeat() function: usage variations - complex strings containing other than 7-bit chars +--INI-- +precision=14 +--FILE-- + +DONE +--EXPECT-- +bool(true) +string(42) "008081eaebfeff008081eaebfeff008081eaebfeff" +string(42) "008081eaebfeff008081eaebfeff008081eaebfeff" +DONE diff --git a/ext/standard/tests/strings/str_split_variation6.phpt b/ext/standard/tests/strings/str_split_variation6.phpt index 1aea668026310..111eb11858aa4 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 (\Error $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_variation6_64bit.phpt b/ext/standard/tests/strings/str_split_variation6_64bit.phpt index 583c7db3cf65f..e6893e9263ea5 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 (\Error $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.phpt b/ext/standard/tests/strings/str_split_variation7.phpt index 1a2471a20a88b..a810dd7ecb4d0 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 diff --git a/ext/standard/tests/strings/str_split_variation7_64bit.phpt b/ext/standard/tests/strings/str_split_variation7_64bit.phpt index bff61adb30244..1a1980028a214 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/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 diff --git a/ext/standard/tests/strings/strpbrk_error.phpt b/ext/standard/tests/strings/strpbrk_error.phpt index cce843c2f1858..c81f809a1c423 100644 --- a/ext/standard/tests/strings/strpbrk_error.phpt +++ b/ext/standard/tests/strings/strpbrk_error.phpt @@ -8,20 +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"; -var_dump( strpbrk($haystack, '') ); +echo "-- Testing strpbrk() function with empty second argument --\n"; + +try { + strpbrk($haystack, ''); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} ?> ===DONE=== --EXPECTF-- -*** 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_variation1.phpt b/ext/standard/tests/strings/strpos_variation1.phpt new file mode 100644 index 0000000000000..42ae9537a2967 --- /dev/null +++ b/ext/standard/tests/strings/strpos_variation1.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test strpos() function : usage variations - complex strings containing other than 7-bit chars +--INI-- +precision=14 +--FILE-- + "; +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_variation1.phpt b/ext/standard/tests/strings/strstr_variation1.phpt new file mode 100644 index 0000000000000..8ea2945bed60b --- /dev/null +++ b/ext/standard/tests/strings/strstr_variation1.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test strstr() function : usage variations - complex strings containing other than 7-bit chars +--FILE-- + "; +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..b0a8a5b0eb509 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 (\Error $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..385689e697050 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 (\Error $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..8c2b08f0462e7 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..f0fa80f63d440 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 (\Error $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 --