strrchr_variation9.phpt [plain text]
--TEST--
Test strrchr() function : usage variations - unexpected inputs for haystack
--FILE--
<?php
echo "*** Testing strrchr() function: with unexpected inputs for haystack ***\n";
$unset_var = 'string_val';
unset($unset_var);
class sample {
public function __toString() {
return "object";
}
}
$file_handle = fopen(__FILE__, "r");
$haystacks = array (
0,
1,
12345,
-2345,
10.5,
-10.5,
10.5e10,
10.6E-10,
.5,
array(),
array(0),
array(1),
array(1, 2),
array('color' => 'red', 'item' => 'pen'),
true,
false,
TRUE,
FALSE,
NULL,
null,
new sample(),
"",
'',
$file_handle,
@$undefined_var,
@$unset_var
);
$needles = array (
"0",
"1",
"2",
"-2",
"10.5",
"-10.5",
"10.5e10",
"10.6E-10",
".5",
"array",
"a",
"r",
"y",
"ay",
"true",
"false",
"TRUE",
"FALSE",
"NULL",
"null",
"object",
"",
'',
"\$file_handle",
@"$undefined_var",
@"$unset_var"
);
$count = 1;
for($index = 0; $index < count($haystacks); $index++) {
echo "-- Iteration $count --\n";
var_dump( strrchr($haystacks[$index], $needles[$index]) );
$count ++;
}
fclose($file_handle);
echo "*** Done ***";
?>
--EXPECTF--
*** Testing strrchr() function: with unexpected inputs for haystack ***
-- Iteration 1 --
string(1) "0"
-- Iteration 2 --
string(1) "1"
-- Iteration 3 --
string(4) "2345"
-- Iteration 4 --
string(5) "-2345"
-- Iteration 5 --
string(4) "10.5"
-- Iteration 6 --
string(5) "-10.5"
-- Iteration 7 --
string(12) "105000000000"
-- Iteration 8 --
string(7) "1.06E-9"
-- Iteration 9 --
string(2) ".5"
-- Iteration 10 --
Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 11 --
Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 12 --
Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 13 --
Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 14 --
Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 15 --
bool(false)
-- Iteration 16 --
bool(false)
-- Iteration 17 --
bool(false)
-- Iteration 18 --
bool(false)
-- Iteration 19 --
bool(false)
-- Iteration 20 --
bool(false)
-- Iteration 21 --
string(6) "object"
-- Iteration 22 --
bool(false)
-- Iteration 23 --
bool(false)
-- Iteration 24 --
Warning: strrchr() expects parameter 1 to be string, resource given in %s on line %d
NULL
-- Iteration 25 --
bool(false)
-- Iteration 26 --
bool(false)
*** Done ***