Convert Errors to ValueErrors

Closes GH-4930
This commit is contained in:
George Peter Banyard 2019-11-18 23:40:02 +01:00
parent 73730eebca
commit 5fbd49f9ab
52 changed files with 125 additions and 207 deletions

View file

@ -1263,7 +1263,7 @@ PHP_FUNCTION(min)
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 0)) != NULL) {
ZVAL_COPY_DEREF(return_value, result);
} else {
zend_throw_error(NULL, "Array must contain at least one element");
zend_value_error("Array must contain at least one element");
return;
}
}
@ -1310,7 +1310,7 @@ PHP_FUNCTION(max)
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 1)) != NULL) {
ZVAL_COPY_DEREF(return_value, result);
} else {
zend_throw_error(NULL, "Array must contain at least one element");
zend_value_error("Array must contain at least one element");
return;
}
}
@ -2451,18 +2451,18 @@ PHP_FUNCTION(extract)
extract_type &= 0xff;
if (extract_type < EXTR_OVERWRITE || extract_type > EXTR_IF_EXISTS) {
zend_throw_error(NULL, "Invalid extract type");
zend_value_error("Invalid extract type");
return;
}
if (extract_type > EXTR_SKIP && extract_type <= EXTR_PREFIX_IF_EXISTS && ZEND_NUM_ARGS() < 3) {
zend_throw_error(NULL, "Specified extract type requires the prefix parameter");
zend_value_error("Specified extract type requires the prefix parameter");
return;
}
if (prefix) {
if (ZSTR_LEN(prefix) && !php_valid_var_name(ZSTR_VAL(prefix), ZSTR_LEN(prefix))) {
zend_throw_error(NULL, "Prefix is not a valid identifier");
zend_value_error("Prefix is not a valid identifier");
return;
}
}
@ -2619,7 +2619,7 @@ PHP_FUNCTION(array_fill)
if (EXPECTED(num > 0)) {
if (sizeof(num) > 4 && UNEXPECTED(EXPECTED(num > 0x7fffffff))) {
zend_throw_error(NULL, "Too many elements");
zend_value_error("Too many elements");
return;
} else if (UNEXPECTED(start_key > ZEND_LONG_MAX - num + 1)) {
zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
@ -2668,7 +2668,7 @@ PHP_FUNCTION(array_fill)
} else if (EXPECTED(num == 0)) {
RETURN_EMPTY_ARRAY();
} else {
zend_throw_error(NULL, "Number of elements can't be negative");
zend_value_error("Number of elements can't be negative");
return;
}
}
@ -2706,7 +2706,7 @@ PHP_FUNCTION(array_fill_keys)
#define RANGE_CHECK_DOUBLE_INIT_ARRAY(start, end) do { \
double __calc_size = ((start - end) / step) + 1; \
if (__calc_size >= (double)HT_MAX_SIZE) { \
zend_throw_error(NULL, \
zend_value_error(\
"The supplied range exceeds the maximum array size: start=%0.0f end=%0.0f", end, start); \
return; \
} \
@ -2718,7 +2718,7 @@ PHP_FUNCTION(array_fill_keys)
#define RANGE_CHECK_LONG_INIT_ARRAY(start, end) do { \
zend_ulong __calc_size = ((zend_ulong) start - end) / lstep; \
if (__calc_size >= HT_MAX_SIZE - 1) { \
zend_throw_error(NULL, \
zend_value_error(\
"The supplied range exceeds the maximum array size: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT, end, start); \
return; \
} \
@ -2816,7 +2816,7 @@ double_str:
high = zval_get_double(zhigh);
if (zend_isinf(high) || zend_isinf(low)) {
zend_throw_error(NULL, "Invalid range supplied: start=%0.0f end=%0.0f", low, high);
zend_value_error("Invalid range supplied: start=%0.0f end=%0.0f", low, high);
return;
}
@ -2909,7 +2909,7 @@ long_str:
}
err:
if (err) {
zend_throw_error(NULL, "step exceeds the specified range");
zend_value_error("step exceeds the specified range");
return;
}
}
@ -4389,7 +4389,7 @@ PHP_FUNCTION(array_pad)
input_size = zend_hash_num_elements(Z_ARRVAL_P(input));
pad_size_abs = ZEND_ABS(pad_size);
if (pad_size_abs < 0 || pad_size_abs - input_size > Z_L(1048576)) {
zend_throw_error(NULL, "You may only pad up to 1048576 elements at a time");
zend_value_error("You may only pad up to 1048576 elements at a time");
return;
}
@ -5769,7 +5769,7 @@ PHP_FUNCTION(array_multisort)
array_size = zend_hash_num_elements(Z_ARRVAL_P(arrays[0]));
for (i = 0; i < num_arrays; i++) {
if (zend_hash_num_elements(Z_ARRVAL_P(arrays[i])) != (uint32_t)array_size) {
zend_throw_error(NULL, "Array sizes are inconsistent");
zend_value_error("Array sizes are inconsistent");
MULTISORT_ABORT;
}
}
@ -5865,7 +5865,7 @@ PHP_FUNCTION(array_rand)
num_avail = zend_hash_num_elements(Z_ARRVAL_P(input));
if (num_avail == 0) {
zend_throw_error(NULL, "Array is empty");
zend_value_error("Array is empty");
return;
}
@ -5906,7 +5906,7 @@ PHP_FUNCTION(array_rand)
}
if (num_req <= 0 || num_req > num_avail) {
zend_throw_error(NULL, "Second argument has to be between 1 and the number of elements in the array");
zend_value_error("Second argument has to be between 1 and the number of elements in the array");
return;
}
@ -6395,7 +6395,7 @@ PHP_FUNCTION(array_chunk)
/* Do bounds checking for size parameter. */
if (size < 1) {
zend_throw_error(NULL, "Size parameter expected to be greater than 0");
zend_value_error("Size parameter expected to be greater than 0");
return;
}
@ -6460,7 +6460,7 @@ PHP_FUNCTION(array_combine)
num_values = zend_hash_num_elements(values);
if (num_keys != num_values) {
zend_throw_error(NULL, "Both parameters should have an equal number of elements");
zend_value_error("Both parameters should have an equal number of elements");
return;
}

View file

@ -314,7 +314,7 @@ PHP_FUNCTION(assert_options)
break;
default:
zend_throw_error(NULL, "Unknown value " ZEND_LONG_FMT, what);
zend_value_error("Unknown value " ZEND_LONG_FMT, what);
break;
}

View file

@ -559,7 +559,7 @@ PHP_FUNCTION(scandir)
ZEND_PARSE_PARAMETERS_END();
if (dirn_len < 1) {
zend_throw_error(NULL, "Directory name cannot be empty");
zend_value_error("Directory name cannot be empty");
return;
}

View file

@ -931,12 +931,12 @@ PHP_FUNCTION(wordwrap)
}
if (breakchar_len == 0) {
zend_throw_error(NULL, "Break string cannot be empty");
zend_value_error("Break string cannot be empty");
return;
}
if (linelength == 0 && docut) {
zend_throw_error(NULL, "Can't force cut when width is zero");
zend_value_error("Can't force cut when width is zero");
return;
}
@ -1143,7 +1143,7 @@ PHP_FUNCTION(explode)
ZEND_PARSE_PARAMETERS_END();
if (ZSTR_LEN(delim) == 0) {
zend_throw_error(NULL, "Empty delimiter");
zend_value_error("Empty delimiter");
return;
}
@ -1642,7 +1642,7 @@ PHP_FUNCTION(dirname)
ZSTR_LEN(ret) = zend_dirname(ZSTR_VAL(ret), str_len);
#endif
} else if (levels < 1) {
zend_throw_error(NULL, "Invalid argument, levels must be >= 1");
zend_value_error("Invalid argument, levels must be >= 1");
zend_string_efree(ret);
return;
} else {
@ -2155,7 +2155,7 @@ PHP_FUNCTION(chunk_split)
ZEND_PARSE_PARAMETERS_END();
if (chunklen <= 0) {
zend_throw_error(NULL, "Chunk length should be greater than zero");
zend_value_error("Chunk length should be greater than zero");
return;
}
@ -5287,7 +5287,7 @@ PHP_FUNCTION(str_repeat)
ZEND_PARSE_PARAMETERS_END();
if (mult < 0) {
zend_throw_error(NULL, "Second argument has to be greater than or equal to 0");
zend_value_error("Second argument has to be greater than or equal to 0");
return;
}
@ -5534,7 +5534,7 @@ PHP_FUNCTION(substr_count)
ZEND_PARSE_PARAMETERS_END();
if (needle_len == 0) {
zend_throw_error(NULL, "Empty substring");
zend_value_error("Empty substring");
return;
}
@ -5611,12 +5611,12 @@ PHP_FUNCTION(str_pad)
}
if (pad_str_len == 0) {
zend_throw_error(NULL, "Padding string cannot be empty");
zend_value_error("Padding string cannot be empty");
return;
}
if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH) {
zend_throw_error(NULL, "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH");
zend_value_error("Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH");
return;
}
@ -5876,7 +5876,7 @@ PHP_FUNCTION(str_word_count)
/* nothing to be done */
break;
default:
zend_throw_error(NULL, "Invalid format value " ZEND_LONG_FMT, type);
zend_value_error("Invalid format value " ZEND_LONG_FMT, type);
return;
}
@ -5941,7 +5941,7 @@ PHP_FUNCTION(str_split)
ZEND_PARSE_PARAMETERS_END();
if (split_length <= 0) {
zend_throw_error(NULL, "The length of each segment must be greater than zero");
zend_value_error("The length of each segment must be greater than zero");
return;
}
@ -6020,7 +6020,7 @@ PHP_FUNCTION(substr_compare)
if (len == 0) {
RETURN_LONG(0L);
} else {
zend_throw_error(NULL, "The length must be greater than or equal to zero");
zend_value_error("The length must be greater than or equal to zero");
return;
}
}

View file

@ -6,13 +6,13 @@ $input_array = array('a', 'b', 'c', 'd', 'e');
try {
var_dump(array_chunk($input_array, 0));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(array_chunk($input_array, 0, true));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}

View file

@ -29,23 +29,22 @@ foreach ($sizes as $size){
echo "\n-- Testing array_chunk() when size = $size --\n";
try {
var_dump( array_chunk($input_array, $size) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump( array_chunk($input_array, $size, true) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump( array_chunk($input_array, $size, false) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
}
?>
DONE
--EXPECT--
*** Testing array_chunk() : usage variations ***
@ -146,5 +145,3 @@ array(3) {
int(3)
}
}
DONE

View file

@ -18,7 +18,7 @@ var_dump( array_combine(array(), array()) );
echo "\n-- Testing array_combine() function with empty array for \$keys argument --\n";
try {
var_dump( array_combine(array(), array(1, 2)) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage();
}
@ -26,7 +26,7 @@ try {
echo "\n-- Testing array_combine() function with empty array for \$values argument --\n";
try {
var_dump( array_combine(array(1, 2), array()) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage();
}
@ -34,13 +34,11 @@ try {
echo "\n-- Testing array_combine() function by passing array with unequal number of elements --\n";
try {
var_dump( array_combine(array(1, 2), array(1, 2, 3)) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage();
}
?>
DONE
--EXPECT--
*** Testing array_combine() : error conditions specific to array_combine() ***
@ -54,4 +52,3 @@ Both parameters should have an equal number of elements
Both parameters should have an equal number of elements
-- Testing array_combine() function by passing array with unequal number of elements --
Both parameters should have an equal number of elements
DONE

View file

@ -17,15 +17,11 @@ $val = 1;
try {
var_dump( array_fill($start_key,$num,$val) );
} catch (Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
?>
DONE
--EXPECTF--
--EXPECT--
*** Testing array_fill() : error conditions ***
Number of elements can't be negative
DONE

View file

@ -14,7 +14,7 @@ echo "\n-- Testing array_multisort() function with repeated flags --\n";
$ar1 = array(1);
try {
var_dump( array_multisort($ar1, SORT_ASC, SORT_ASC) );
} catch (Error $e) {
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}
@ -22,7 +22,7 @@ echo "\n-- Testing array_multisort() function with repeated flags --\n";
$ar1 = array(1);
try {
var_dump( array_multisort($ar1, SORT_STRING, SORT_NUMERIC) );
} catch (Error $e) {
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}

View file

@ -99,7 +99,7 @@ foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
try {
var_dump( array_multisort($value));
} catch (Error $e) {
} catch (\ValueError | \TypeError $e) {
echo $e->getMessage() . "\n";
}
};

View file

@ -107,7 +107,7 @@ foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
try {
var_dump( array_multisort($ar1, $value) );
} catch (Error $e) {
} catch (\ValueError | \TypeError $e) {
echo $e->getMessage() . "\n";
}
};

View file

@ -99,7 +99,7 @@ foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
try {
var_dump( array_multisort($ar1, SORT_REGULAR, $value) );
} catch (Error $e) {
} catch (\ValueError | \TypeError $e) {
echo $e->getMessage() . "\n";
}
};

View file

@ -15,13 +15,11 @@ var_dump(array_pad(array("", -1, 2.0), -4, array()));
try {
var_dump(array_pad(array("", -1, 2.0), 2000000, 0));
} catch (Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
?>
DONE
--EXPECT--
array(1) {
[0]=>
@ -87,5 +85,3 @@ array(4) {
float(2)
}
You may only pad up to 1048576 elements at a time
DONE

View file

@ -22,7 +22,6 @@ try {
}
var_dump($array);
echo "Done";
?>
--EXPECTF--
*** Testing array_push() : error conditions ***
@ -31,4 +30,3 @@ array(1) {
[%d]=>
string(3) "max"
}
Done

View file

@ -5,38 +5,37 @@ array_rand() tests
try {
var_dump(array_rand(array()));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(array_rand(array(), 0));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(array_rand(array(1,2,3), 0));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(array_rand(array(1,2,3), -1));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(array_rand(array(1,2,3), 10));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
var_dump(array_rand(array(1,2,3), 3));
var_dump(array_rand(array(1,2,3), 2));
echo "Done\n";
?>
--EXPECTF--
Array is empty
@ -58,4 +57,3 @@ array(2) {
[1]=>
int(%d)
}
Done

View file

@ -34,34 +34,32 @@ var_dump( array_rand($input, 1) ); // with valid $num_req value
echo"\n-- With num_req = 0 --\n";
try {
var_dump( array_rand($input, 0) ); // with $num_req=0
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
echo"\n-- With num_req = -1 --\n";
try {
var_dump( array_rand($input, -1) ); // with $num_req=-1
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
echo"\n-- With num_req = -2 --\n";
try {
var_dump( array_rand($input, -2) ); // with $num_req=-2
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
echo"\n-- With num_req more than number of members in 'input' array --\n";
try {
var_dump( array_rand($input, 13) ); // with $num_req=13
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
?>
DONE
--EXPECTF--
*** Testing array_rand() : with invalid values for 'req_num' ***
@ -82,5 +80,3 @@ Second argument has to be between 1 and the number of elements in the array
-- With num_req more than number of members in 'input' array --
Second argument has to be between 1 and the number of elements in the array
DONE

View file

@ -20,9 +20,5 @@ $a["key1"]["key2"]["key3"] = null;
$b["key1"]["key2"]["key3"] = null;
?>
DONE
--EXPECT--
Recursion detected
DONE

View file

@ -10,7 +10,5 @@ try {
}
?>
OKAY
--EXPECT--
Cannot call compact() dynamically
OKAY

View file

@ -13,7 +13,7 @@ $data = [['aa'=> 'bb',], ['aa'=> 'bb',],];
try {
array_multisort(array_column($data, 'bb'),SORT_DESC, $data); // PHP Warning error
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
?>

View file

@ -23,24 +23,19 @@ $arr3 = array(&$string);
try {
var_dump(compact($arr1));
} catch (\Error $e) {
} catch (Error $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(compact($arr2));
} catch (\Error $e) {
} catch (Error $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(compact($arr3));
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
var_dump(compact($arr3));
?>
DONE
--EXPECT--
*** Testing compact() : usage variations - arrays containing references ***
Recursion detected
@ -49,5 +44,3 @@ array(1) {
["c"]=>
int(3)
}
DONE

View file

@ -11,24 +11,23 @@ $arr = array(1);
try {
var_dump( extract($arr, -1 . "wddr") );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump( extract($arr, 7 , "wddr") );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
/* Two Arguments, second as prefix but without prefix string as third argument */
try {
var_dump( extract($arr,EXTR_PREFIX_IF_EXISTS) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
echo "Done\n";
?>
--EXPECTF--
*** Testing Error Conditions ***
@ -37,4 +36,3 @@ Notice: A non well formed numeric value encountered in %s on line %d
Invalid extract type
Invalid extract type
Specified extract type requires the prefix parameter
Done

View file

@ -6,7 +6,7 @@ $a = ["1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five"];
try {
extract($a, EXTR_PREFIX_ALL, '85bogus');
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage();
}
?>

View file

@ -13,7 +13,7 @@ try {
try {
var_dump(max(array()));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
@ -31,7 +31,6 @@ var_dump(max(true, false, true));
var_dump(max(1, true, false, true));
var_dump(max(0, true, false, true));
echo "Done\n";
?>
--EXPECT--
When only one parameter is given, it must be an array
@ -44,4 +43,3 @@ bool(true)
bool(true)
int(1)
bool(true)
Done

View file

@ -13,7 +13,7 @@ try {
try {
var_dump(min(array()));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
@ -31,7 +31,6 @@ var_dump(min(true, false, true));
var_dump(min(1, true, false, true));
var_dump(min(0, true, false, true));
echo "Done\n";
?>
--EXPECT--
When only one parameter is given, it must be an array
@ -44,4 +43,3 @@ bool(false)
bool(false)
bool(false)
int(0)
Done

View file

@ -4,7 +4,7 @@ Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var
<?php
try {
range(0, pow(2.0, 100000000));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
?>

View file

@ -4,7 +4,7 @@ Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var
<?php
try {
range(pow(2.0, 100000000), pow(2.0, 100000000) + 1);
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
?>

View file

@ -4,7 +4,7 @@ Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var
<?php
try {
var_dump(range(0, PHP_INT_MAX));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
?>

View file

@ -4,7 +4,7 @@ Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var
<?php
try {
var_dump(range(PHP_INT_MIN, 0));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
?>

View file

@ -10,67 +10,65 @@ echo "\n*** Testing error conditions ***\n";
echo "\n-- Testing ( (low < high) && (step = 0) ) --\n";
try {
var_dump( range(1, 2, 0) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump( range("a", "b", 0) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage(), "\n";
}
echo "\n\n-- Testing ( (low > high) && (step = 0) ) --\n";
try {
var_dump( range(2, 1, 0) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump( range("b", "a", 0) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage(), "\n";
}
echo "\n\n-- Testing ( (low < high) && (high-low < step) ) --\n";
try {
var_dump( range(1.0, 7.0, 6.5) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage(), "\n";
}
echo "\n\n-- Testing ( (low > high) && (low-high < step) ) --\n";
try {
var_dump( range(7.0, 1.0, 6.5) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage(), "\n";
}
echo "\n-- Testing other conditions --\n";
try {
var_dump( range(-1, -2, 2) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump( range("a", "j", "z") );
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
} catch (\Error $e) {
} catch (\TypeError $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump( range(0, 1, "140962482048819216326.24") );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump( range(0, 1, "140962482048819216326.24.") );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage(), "\n";
}
@ -80,14 +78,10 @@ $step_arr = array( "string", NULL, FALSE, "", "\0" );
foreach( $step_arr as $step ) {
try {
var_dump( range( 1, 5, $step ) );
} catch (\TypeError $e) {
echo $e->getMessage(), "\n";
} catch (\Error $e) {
} catch (\TypeError | \ValueError $e) {
echo $e->getMessage(), "\n";
}
}
echo "Done\n";
?>
--EXPECTF--
*** Testing error conditions ***
@ -123,4 +117,3 @@ step exceeds the specified range
step exceeds the specified range
range() expects parameter 3 to be int or float, string given
range() expects parameter 3 to be int or float, string given
Done

View file

@ -5,7 +5,7 @@ assert_options() - unknown assert option.
<?php
try {
assert_options(1000);
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage();
}
?>

View file

@ -5,7 +5,7 @@ Bug #41693 (scandir() allows empty directory names)
try {
var_dump(scandir(''));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}

View file

@ -63,4 +63,3 @@ Directory::close(): supplied argument is not a valid Directory resource
Unable to find my handle property
Unable to find my handle property
Unable to find my handle property

View file

@ -4,10 +4,10 @@ Bug #33605 (substr_compare crashes)
<?php
try {
substr_compare("aa", "a", -99999999, -1, 0);
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage();
}
?>
--EXPECTF--
--EXPECT--
The length must be greater than or equal to zero

View file

@ -50,14 +50,13 @@ 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) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
}
echo "Done"
?>
--EXPECTF--
--EXPECT--
*** Testing chunk_split() : different 'chunklen' with heredoc 'str' ***
-- Iteration 1 --
Chunk length should be greater than zero
@ -87,4 +86,3 @@ chunk_split():::"
chunk_split() expects parameter 2 to be int, float given
-- Iteration 8 --
Chunk length should be greater than zero
Done

View file

@ -10,13 +10,11 @@ echo "*** Testing error conditions ***\n";
// Bad arg
try {
dirname("/var/tmp/bar.gz", 0);
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
echo "Done\n";
?>
--EXPECTF--
--EXPECT--
*** Testing error conditions ***
Invalid argument, levels must be >= 1
Done

View file

@ -13,18 +13,16 @@ if((substr(PHP_OS, 0, 3) == "WIN"))
for ($i=0 ; $i<5 ; $i++) {
try {
var_dump(dirname("/foo/bar/baz", $i));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
}
var_dump(dirname("/foo/bar/baz", PHP_INT_MAX));
?>
Done
--EXPECTF--
--EXPECT--
Invalid argument, levels must be >= 1
string(8) "/foo/bar"
string(4) "/foo"
string(1) "/"
string(1) "/"
string(1) "/"
Done

View file

@ -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 (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
}
@ -23,7 +23,6 @@ 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
--EXPECT--
Invalid argument, levels must be >= 1
string(8) "/foo/bar"
@ -33,4 +32,3 @@ string(1) "\"
string(1) "\"
string(3) "g:\"
string(3) "g:."
Done

View file

@ -14,17 +14,17 @@ echo "\n";
try {
var_dump(explode("", ""));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(explode("", NULL));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(explode(NULL, ""));
} catch (\Error $e) {
} catch (\ValueError $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 (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
var_dump(explode("abc", "acb"));

View file

@ -36,22 +36,22 @@ foreach($delimiters as $delimiter) {
try {
var_dump( explode($delimiter, $string, -1) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump( explode($delimiter, $string, 0) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump( explode($delimiter, $string, 1) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump( explode($delimiter, $string, 2) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
$counter++;
@ -94,9 +94,8 @@ class string1 {
$obj = new string1;
var_dump( explode("b", $obj) );
echo "Done\n";
?>
--EXPECTF--
--EXPECT--
*** Testing explode() for basic operations ***
-- Iteration 1 --
Empty delimiter
@ -486,4 +485,3 @@ array(2) {
[1]=>
string(4) "ject"
}
Done

View file

@ -67,13 +67,13 @@ echo "\n--- padding string as null ---\n";
try {
str_pad($input_string, 12, NULL);
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
str_pad($input_string, 12, "");
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
@ -81,11 +81,10 @@ try {
try {
str_pad($input_string, $pad_length, "+", 15);
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
echo "Done\n";
?>
--EXPECT--
#### Basic operations ####
@ -343,4 +342,3 @@ string(16) "\t\variation\t\t"
Padding string cannot be empty
Padding string cannot be empty
Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH
Done

View file

@ -39,11 +39,10 @@ for($count = 0; $count < count($values); $count++) {
try {
var_dump( str_split($str, $values[$count]) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
}
echo "Done"
?>
--EXPECT--
*** Testing str_split() : different integer values for 'split_length' ***
@ -157,4 +156,3 @@ array(1) {
}
-- Iteration 7 --
The length of each segment must be greater than zero
Done

View file

@ -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' 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';
@ -39,14 +39,13 @@ for($count = 0; $count < count($values); $count++) {
echo "-- Iteration ".($count + 1)." --\n";
try {
var_dump( str_split($str, $values[$count]) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
}
echo "Done"
?>
--EXPECT--
*** Testing str_split() : different intger values for 'split_length' ***
*** Testing str_split() : different integer values for 'split_length' ***
-- Iteration 1 --
The length of each segment must be greater than zero
-- Iteration 2 --
@ -162,4 +161,3 @@ array(1) {
}
-- Iteration 8 --
The length of each segment must be greater than zero
Done

View file

@ -41,11 +41,10 @@ for($count = 0; $count < count($values); $count++) {
try {
var_dump( str_split($str, $values[$count]) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
}
echo "Done"
?>
--EXPECT--
*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' ***
@ -135,4 +134,3 @@ array(1) {
}
-- Iteration 7 --
The length of each segment must be greater than zero
Done

View file

@ -41,11 +41,10 @@ for($count = 0; $count < count($values); $count++) {
echo "-- Iteration ".($count + 1)." --\n";
try {
var_dump( str_split($str, $values[$count]) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
}
echo "Done"
?>
--EXPECT--
*** Testing str_split() : different integer values for 'split_length' with heredoc 'str' ***
@ -140,4 +139,3 @@ array(1) {
}
-- Iteration 8 --
The length of each segment must be greater than zero
Done

View file

@ -11,25 +11,25 @@ var_dump(str_word_count($str));
try {
var_dump(str_word_count($str, 3));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(str_word_count($str, 123));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(str_word_count($str, -1));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(str_word_count($str, 999999999));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}

View file

@ -7,20 +7,18 @@ var_dump(str_word_count(""));
try {
var_dump(str_word_count("", -1));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(str_word_count("", -1, $a));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
var_dump($a);
?>
DONE
--EXPECTF--
int(0)
Invalid format value -1
@ -30,5 +28,3 @@ Invalid format value -1
Warning: Undefined variable: a in %s on line %d
NULL
DONE

View file

@ -17,14 +17,12 @@ echo "Test\n";
try {
substr_compare("abcde", "abc", 0, -1);
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
var_dump(substr_compare("abcde", "abc", -1, NULL, -5) > 0);
echo "Done\n";
?>
--EXPECTF--
--EXPECT--
bool(true)
bool(true)
int(0)
@ -38,4 +36,3 @@ int(0)
Test
The length must be greater than or equal to zero
bool(true)
Done

View file

@ -6,12 +6,12 @@ Test substr_count() function (basic)
echo "***Testing basic operations ***\n";
try {
substr_count("", "");
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
substr_count("a", "");
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
var_dump(substr_count("", "a"));
@ -31,8 +31,6 @@ var_dump(substr_count($a, "bca", -200, null));
var_dump(substr_count($a, "bca", -200, 50));
var_dump(substr_count($a, "bca", -200, -50));
echo "Done\n";
?>
--EXPECT--
***Testing basic operations ***
@ -50,4 +48,3 @@ int(40)
int(40)
int(10)
int(30)
Done

View file

@ -35,7 +35,7 @@ echo "\n";
try {
wordwrap(chr(0), 0, "");
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
--EXPECT--

View file

@ -29,7 +29,7 @@ $cut = true;
try {
wordwrap($str, $width, $break, $cut);
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
@ -44,10 +44,8 @@ echo "-- width = -10 & cut = true --\n";
$width = -10;
$cut = true;
var_dump( wordwrap($str, $width, $break, $cut) );
echo "Done\n";
?>
--EXPECTF--
--EXPECT--
*** Testing wordwrap() : error conditions ***
-- Testing wordwrap() function with negative/zero value for width argument --
@ -59,4 +57,3 @@ Can't force cut when width is zero
string(39) "testing<br />\nwordwrap<br />\nfunction"
-- width = -10 & cut = true --
string(223) "<br />\nt<br />\ne<br />\ns<br />\nt<br />\ni<br />\nn<br />\ng<br />\n<br />\nw<br />\no<br />\nr<br />\nd<br />\nw<br />\nr<br />\na<br />\np<br />\n<br />\nf<br />\nu<br />\nn<br />\nc<br />\nt<br />\ni<br />\no<br />\nn"
Done