sscanf_variation1.phpt [plain text]
--TEST--
Test sscanf() function : usage variations - unexpected inputs for '$str' argument
--FILE--
<?php
echo "*** Testing sscanf() function: with unexpected inputs for 'str' argument ***\n";
$unset_var = 'string_val';
unset($unset_var);
class sample {
public function __toString() {
return "sample object";
}
}
$file_handle = fopen(__FILE__, "r");
$inputs = array (
0,
1,
-2,
2147483647,
-2147483648,
10.5,
-20.5,
10.1234567e10,
array(),
array(0),
array(1, 2),
true,
false,
TRUE,
FALSE,
NULL,
null,
new sample(),
$file_handle,
@$undefined_var,
@$unset_var
);
$format = "%s";
$count = 1;
foreach($inputs as $input) {
echo "-- Iteration $count --\n";
var_dump( sscanf($input, $format) );
$count ++;
}
fclose($file_handle);
?>
===DONE===
--EXPECTF--
*** Testing sscanf() function: with unexpected inputs for 'str' argument ***
-- Iteration 1 --
array(1) {
[0]=>
string(1) "0"
}
-- Iteration 2 --
array(1) {
[0]=>
string(1) "1"
}
-- Iteration 3 --
array(1) {
[0]=>
string(2) "-2"
}
-- Iteration 4 --
array(1) {
[0]=>
string(10) "2147483647"
}
-- Iteration 5 --
array(1) {
[0]=>
string(11) "-2147483648"
}
-- Iteration 6 --
array(1) {
[0]=>
string(4) "10.5"
}
-- Iteration 7 --
array(1) {
[0]=>
string(5) "-20.5"
}
-- Iteration 8 --
array(1) {
[0]=>
string(12) "101234567000"
}
-- Iteration 9 --
Warning: sscanf() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 10 --
Warning: sscanf() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 11 --
Warning: sscanf() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 12 --
array(1) {
[0]=>
string(1) "1"
}
-- Iteration 13 --
NULL
-- Iteration 14 --
array(1) {
[0]=>
string(1) "1"
}
-- Iteration 15 --
NULL
-- Iteration 16 --
NULL
-- Iteration 17 --
NULL
-- Iteration 18 --
array(1) {
[0]=>
string(6) "sample"
}
-- Iteration 19 --
Warning: sscanf() expects parameter 1 to be string, resource given in %s on line %d
NULL
-- Iteration 20 --
NULL
-- Iteration 21 --
NULL
===DONE===