php-src/ext/standard/tests/strings/strtr_variation6.phpt

127 lines
2.6 KiB
Plaintext
Raw Normal View History

2007-10-08 15:21:36 +00:00
--TEST--
Test strtr() function : usage variations - unexpected inputs for 'from' argument
--FILE--
<?php
2018-10-14 16:03:31 +00:00
/* Test strtr() function: with unexpected inputs for 'from'
* and expected type for 'str' & 'to' arguments
2007-10-08 15:21:36 +00:00
*/
echo "*** Testing strtr() function: with unexpected inputs for 'from' ***\n";
//get an unset variable
$unset_var = 'string_val';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return "sample object";
2018-09-16 17:16:42 +00:00
}
2007-10-08 15:21:36 +00:00
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
//defining 'str' argument
$str = "012atm";
// array of values for 'from'
$from_arr = array (
2020-02-03 21:52:20 +00:00
// integer values
/*1*/ 0,
2020-02-03 21:52:20 +00:00
1,
-2,
2018-09-16 17:16:42 +00:00
2020-02-03 21:52:20 +00:00
// float values
/*4*/ 10.5,
2020-02-03 21:52:20 +00:00
-20.5,
10.1234567e10,
2018-09-16 17:16:42 +00:00
2020-02-03 21:52:20 +00:00
// array values
/*7*/ array(),
2020-02-03 21:52:20 +00:00
array(0),
array(1, 2),
2018-09-16 17:16:42 +00:00
2020-02-03 21:52:20 +00:00
// boolean values
/*10*/ true,
2020-02-03 21:52:20 +00:00
false,
TRUE,
FALSE,
2018-09-16 17:16:42 +00:00
2020-02-03 21:52:20 +00:00
// null values
/*14*/ NULL,
2020-02-03 21:52:20 +00:00
null,
2018-09-16 17:16:42 +00:00
2020-02-03 21:52:20 +00:00
// objects
/*16*/ new sample(),
2018-09-16 17:16:42 +00:00
2020-02-03 21:52:20 +00:00
// resource
/*17*/ $file_handle,
2018-09-16 17:16:42 +00:00
2020-02-03 21:52:20 +00:00
// undefined variable
/*18*/ @$undefined_var,
2018-09-16 17:16:42 +00:00
2020-02-03 21:52:20 +00:00
// unset variable
/*19*/ @$unset_var
2007-10-08 15:21:36 +00:00
);
//defining 'to' argument
$to = "atm012";
// loop through with each element of the $from array to test strtr() function
$count = 1;
for($index = 0; $index < count($from_arr); $index++) {
echo "-- Iteration $count --\n";
$from = $from_arr[$index];
try {
var_dump(strtr($str, $from, $to));
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}
$count++;
2007-10-08 15:21:36 +00:00
}
fclose($file_handle); //closing the file handle
?>
--EXPECT--
2007-10-08 15:21:36 +00:00
*** Testing strtr() function: with unexpected inputs for 'from' ***
-- Iteration 1 --
string(6) "a12atm"
-- Iteration 2 --
string(6) "0a2atm"
-- Iteration 3 --
string(6) "01tatm"
-- Iteration 4 --
string(6) "ta2atm"
-- Iteration 5 --
string(6) "m1tatm"
-- Iteration 6 --
string(6) "tm0atm"
2007-10-08 15:21:36 +00:00
-- Iteration 7 --
strtr(): Argument #2 ($from) must be of type string, array given
2007-10-08 15:21:36 +00:00
-- Iteration 8 --
strtr(): Argument #2 ($from) must be of type string, array given
2007-10-08 15:21:36 +00:00
-- Iteration 9 --
strtr(): Argument #2 ($from) must be of type string, array given
2007-10-08 15:21:36 +00:00
-- Iteration 10 --
string(6) "0a2atm"
-- Iteration 11 --
string(6) "012atm"
-- Iteration 12 --
string(6) "0a2atm"
-- Iteration 13 --
string(6) "012atm"
-- Iteration 14 --
string(6) "012atm"
-- Iteration 15 --
string(6) "012atm"
-- Iteration 16 --
string(6) "012ttm"
-- Iteration 17 --
strtr(): Argument #2 ($from) must be of type array|string, resource given
2007-10-08 15:21:36 +00:00
-- Iteration 18 --
string(6) "012atm"
-- Iteration 19 --
string(6) "012atm"