1--TEST--
2Test sscanf() function : usage variations - unexpected inputs for '$format' argument
3--FILE--
4<?php
5/* Prototype  : mixed sscanf  ( string $str  , string $format  [, mixed &$...  ] )
6 * Description: Parses input from a string according to a format
7 * Source code: ext/standard/string.c
8*/
9
10echo "*** Testing sscanf() function: with unexpected inputs for 'format' argument ***\n";
11
12//get an unset variable
13$unset_var = 'string_val';
14unset($unset_var);
15
16//defining a class
17class sample  {
18  public function __toString() {
19    return "sample object";
20  }
21}
22
23//getting the resource
24$file_handle = fopen(__FILE__, "r");
25
26// array with different values for $input
27$inputs =  array (
28
29		  // integer values
30/*1*/	  0,
31		  1,
32		  -2,
33		   2147483647,
34		  -2147483648,
35
36		  // float values
37/*6*/	  10.5,
38		  -20.5,
39		  10.1234567e10,
40
41		  // array values
42/*9*/	  array(),
43		  array(0),
44		  array(1, 2),
45
46		  // boolean values
47/*12*/	  true,
48		  false,
49		  TRUE,
50		  FALSE,
51
52		  // null values
53/*16*/	  NULL,
54		  null,
55
56		  // objects
57/*18*/	  new sample(),
58
59		  // resource
60/*19*/	  $file_handle,
61
62		  // undefined variable
63/*20*/	  @$undefined_var,
64
65		  // unset variable
66/*21*/	  @$unset_var
67);
68
69//defining '$pad_length' argument
70$str = "Hello World";
71
72// loop through with each element of the $inputs array to test sscanf() function
73$count = 1;
74foreach($inputs as $input) {
75  echo "-- Iteration $count --\n";
76  var_dump( sscanf($str, $input) );
77  $count ++;
78}
79
80fclose($file_handle);  //closing the file handle
81
82?>
83===DONE===
84--EXPECTF--
85*** Testing sscanf() function: with unexpected inputs for 'format' argument ***
86-- Iteration 1 --
87array(0) {
88}
89-- Iteration 2 --
90array(0) {
91}
92-- Iteration 3 --
93array(0) {
94}
95-- Iteration 4 --
96array(0) {
97}
98-- Iteration 5 --
99array(0) {
100}
101-- Iteration 6 --
102array(0) {
103}
104-- Iteration 7 --
105array(0) {
106}
107-- Iteration 8 --
108array(0) {
109}
110-- Iteration 9 --
111
112Warning: sscanf() expects parameter 2 to be string, array given in %s on line %d
113NULL
114-- Iteration 10 --
115
116Warning: sscanf() expects parameter 2 to be string, array given in %s on line %d
117NULL
118-- Iteration 11 --
119
120Warning: sscanf() expects parameter 2 to be string, array given in %s on line %d
121NULL
122-- Iteration 12 --
123array(0) {
124}
125-- Iteration 13 --
126array(0) {
127}
128-- Iteration 14 --
129array(0) {
130}
131-- Iteration 15 --
132array(0) {
133}
134-- Iteration 16 --
135array(0) {
136}
137-- Iteration 17 --
138array(0) {
139}
140-- Iteration 18 --
141array(0) {
142}
143-- Iteration 19 --
144
145Warning: sscanf() expects parameter 2 to be string, resource given in %s on line %d
146NULL
147-- Iteration 20 --
148array(0) {
149}
150-- Iteration 21 --
151array(0) {
152}
153===DONE===