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