1--TEST--
2Test stripos() function : usage variations - unexpected inputs for 'haystack' and 'needle' arguments
3--FILE--
4<?php
5/* Prototype  : int stripos ( string $haystack, string $needle [, int $offset] );
6 * Description: Find position of first occurrence of a case-insensitive string
7 * Source code: ext/standard/string.c
8*/
9
10/* Test stripos() function with unexpected inputs for 'haystack' and 'needle' arguments */
11
12echo "*** Testing stripos() function with unexpected values for haystack and needle ***\n";
13
14// get an unset variable
15$unset_var = 'string_val';
16unset($unset_var);
17
18// defining a class
19class sample  {
20  public function __toString() {
21    return "object";
22  }
23}
24
25//getting the resource
26$file_handle = fopen(__FILE__, "r");
27
28// array with different values
29$values =  array (
30
31  // integer values
32  0,
33  1,
34  12345,
35  -2345,
36
37  // float values
38  10.5,
39  -10.5,
40  10.5e10,
41  10.6E-10,
42  .5,
43
44  // array values
45  array(),
46  array(0),
47  array(1),
48  array(1, 2),
49  array('color' => 'red', 'item' => 'pen'),
50
51  // boolean values
52  true,
53  false,
54  TRUE,
55  FALSE,
56
57  // objects
58  new sample(),
59
60  // empty string
61  "",
62  '',
63
64  // null vlaues
65  NULL,
66  null,
67
68  // resource
69  $file_handle,
70
71  // undefined variable
72  @$undefined_var,
73
74  // unset variable
75  @$unset_var
76);
77
78
79// loop through each element of the array and check the working of stripos()
80$counter = 1;
81for($index = 0; $index < count($values); $index ++) {
82  echo "-- Iteration $counter --\n";
83  $haystack = $values[$index];
84  var_dump( stripos($values[$index], $values[$index]) );
85  var_dump( stripos($values[$index], $values[$index], 1) );
86  $counter ++;
87}
88
89echo "*** Done ***";
90?>
91--EXPECTF--
92*** Testing stripos() function with unexpected values for haystack and needle ***
93-- Iteration 1 --
94bool(false)
95bool(false)
96-- Iteration 2 --
97bool(false)
98bool(false)
99-- Iteration 3 --
100bool(false)
101bool(false)
102-- Iteration 4 --
103bool(false)
104bool(false)
105-- Iteration 5 --
106bool(false)
107bool(false)
108-- Iteration 6 --
109bool(false)
110bool(false)
111-- Iteration 7 --
112bool(false)
113bool(false)
114-- Iteration 8 --
115bool(false)
116bool(false)
117-- Iteration 9 --
118bool(false)
119bool(false)
120-- Iteration 10 --
121
122Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
123NULL
124
125Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
126NULL
127-- Iteration 11 --
128
129Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
130NULL
131
132Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
133NULL
134-- Iteration 12 --
135
136Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
137NULL
138
139Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
140NULL
141-- Iteration 13 --
142
143Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
144NULL
145
146Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
147NULL
148-- Iteration 14 --
149
150Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
151NULL
152
153Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
154NULL
155-- Iteration 15 --
156bool(false)
157bool(false)
158-- Iteration 16 --
159bool(false)
160
161Warning: stripos(): Offset not contained in string in %s on line %d
162bool(false)
163-- Iteration 17 --
164bool(false)
165bool(false)
166-- Iteration 18 --
167bool(false)
168
169Warning: stripos(): Offset not contained in string in %s on line %d
170bool(false)
171-- Iteration 19 --
172
173Notice: Object of class sample could not be converted to int in %s on line %d
174bool(false)
175
176Notice: Object of class sample could not be converted to int in %s on line %d
177bool(false)
178-- Iteration 20 --
179bool(false)
180
181Warning: stripos(): Offset not contained in string in %s on line %d
182bool(false)
183-- Iteration 21 --
184bool(false)
185
186Warning: stripos(): Offset not contained in string in %s on line %d
187bool(false)
188-- Iteration 22 --
189bool(false)
190
191Warning: stripos(): Offset not contained in string in %s on line %d
192bool(false)
193-- Iteration 23 --
194bool(false)
195
196Warning: stripos(): Offset not contained in string in %s on line %d
197bool(false)
198-- Iteration 24 --
199
200Warning: stripos() expects parameter 1 to be string, resource given in %s on line %d
201NULL
202
203Warning: stripos() expects parameter 1 to be string, resource given in %s on line %d
204NULL
205-- Iteration 25 --
206bool(false)
207
208Warning: stripos(): Offset not contained in string in %s on line %d
209bool(false)
210-- Iteration 26 --
211bool(false)
212
213Warning: stripos(): Offset not contained in string in %s on line %d
214bool(false)
215*** Done ***
216