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
|
2009-01-19 15:46:41 +00:00
|
|
|
/*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
|
2009-01-19 15:46:41 +00:00
|
|
|
/*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
|
2009-01-19 15:46:41 +00:00
|
|
|
/*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
|
2009-01-19 15:46:41 +00:00
|
|
|
/*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
|
2009-01-19 15:46:41 +00:00
|
|
|
/*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
|
2009-01-19 15:46:41 +00:00
|
|
|
/*16*/ new sample(),
|
2018-09-16 17:16:42 +00:00
|
|
|
|
2020-02-03 21:52:20 +00:00
|
|
|
// resource
|
2009-01-19 15:46:41 +00:00
|
|
|
/*17*/ $file_handle,
|
2018-09-16 17:16:42 +00:00
|
|
|
|
2020-02-03 21:52:20 +00:00
|
|
|
// undefined variable
|
2009-01-19 15:46:41 +00:00
|
|
|
/*18*/ @$undefined_var,
|
2018-09-16 17:16:42 +00:00
|
|
|
|
2020-02-03 21:52:20 +00:00
|
|
|
// unset variable
|
2009-01-19 15:46:41 +00:00
|
|
|
/*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];
|
2019-12-09 23:03:02 +00:00
|
|
|
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
|
|
|
|
?>
|
2020-01-29 19:06:13 +00:00
|
|
|
--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 --
|
2009-01-19 15:46:41 +00:00
|
|
|
string(6) "tm0atm"
|
2007-10-08 15:21:36 +00:00
|
|
|
-- Iteration 7 --
|
2020-02-24 19:19:20 +00:00
|
|
|
strtr(): Argument #2 ($from) must be of type string, array given
|
2007-10-08 15:21:36 +00:00
|
|
|
-- Iteration 8 --
|
2020-02-24 19:19:20 +00:00
|
|
|
strtr(): Argument #2 ($from) must be of type string, array given
|
2007-10-08 15:21:36 +00:00
|
|
|
-- Iteration 9 --
|
2020-02-24 19:19:20 +00:00
|
|
|
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 --
|
2020-09-04 12:20:15 +00:00
|
|
|
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"
|