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 vlaues
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 --
98bool(false)
99
100-- Iteration 2 --
101bool(false)
102
103-- Iteration 3 --
104bool(false)
105
106-- Iteration 4 --
107bool(false)
108
109-- Iteration 5 --
110bool(false)
111
112-- Iteration 6 --
113bool(false)
114
115-- Iteration 7 --
116bool(false)
117
118-- Iteration 8 --
119bool(false)
120
121-- Iteration 9 --
122bool(false)
123
124-- Iteration 10 --
125
126Warning: stripos(): needle is not a string or an integer in %s on line %d
127bool(false)
128
129-- Iteration 11 --
130
131Warning: stripos(): needle is not a string or an integer in %s on line %d
132bool(false)
133
134-- Iteration 12 --
135
136Warning: stripos(): needle is not a string or an integer in %s on line %d
137bool(false)
138
139-- Iteration 13 --
140
141Warning: stripos(): needle is not a string or an integer in %s on line %d
142bool(false)
143
144-- Iteration 14 --
145
146Warning: stripos(): needle is not a string or an integer in %s on line %d
147bool(false)
148
149-- Iteration 15 --
150bool(false)
151
152-- Iteration 16 --
153bool(false)
154
155-- Iteration 17 --
156bool(false)
157
158-- Iteration 18 --
159bool(false)
160
161-- Iteration 19 --
162
163Notice: Object of class sample could not be converted to int in %s on line %d
164bool(false)
165
166-- Iteration 20 --
167bool(false)
168
169-- Iteration 21 --
170bool(false)
171
172-- Iteration 22 --
173bool(false)
174
175-- Iteration 23 --
176bool(false)
177
178-- Iteration 24 --
179
180Warning: stripos(): needle is not a string or an integer in %s on line %d
181%s
182
183-- Iteration 25 --
184bool(false)
185
186-- Iteration 26 --
187bool(false)
188*** Done ***
189