1--TEST--
2Test strrpos() function : usage variations - unexpected inputs for 'haystack' and 'needle' arguments
3--FILE--
4<?php
5/* Prototype  : int strrpos ( string $haystack, string $needle [, int $offset] );
6 * Description: Find position of last occurrence of 'needle' in 'haystack'.
7 * Source code: ext/standard/string.c
8*/
9
10/* Test strrpos() function with unexpected inputs for 'haystack' and 'needle' arguments */
11
12echo "*** Testing strrpos() 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 values
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 strrpos()
80$counter = 1;
81for($index = 0; $index < count($values); $index ++) {
82  echo "-- Iteration $counter --\n";
83  $haystack = $values[$index];
84  var_dump( strrpos($values[$index], $values[$index]) );
85  var_dump( strrpos($values[$index], $values[$index], 1) );
86  $counter ++;
87}
88
89echo "*** Done ***";
90?>
91--EXPECTF--
92*** Testing strrpos() function with unexpected values for haystack and needle ***
93-- Iteration 1 --
94
95Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
96bool(false)
97
98Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
99bool(false)
100-- Iteration 2 --
101
102Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
103bool(false)
104
105Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
106bool(false)
107-- Iteration 3 --
108
109Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
110bool(false)
111
112Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
113bool(false)
114-- Iteration 4 --
115
116Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
117bool(false)
118
119Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
120bool(false)
121-- Iteration 5 --
122
123Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
124bool(false)
125
126Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
127bool(false)
128-- Iteration 6 --
129
130Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
131bool(false)
132
133Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
134bool(false)
135-- Iteration 7 --
136
137Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
138bool(false)
139
140Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
141bool(false)
142-- Iteration 8 --
143
144Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
145bool(false)
146
147Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
148bool(false)
149-- Iteration 9 --
150
151Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
152bool(false)
153
154Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
155bool(false)
156-- Iteration 10 --
157
158Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
159bool(false)
160
161Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
162bool(false)
163-- Iteration 11 --
164
165Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
166bool(false)
167
168Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
169bool(false)
170-- Iteration 12 --
171
172Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
173bool(false)
174
175Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
176bool(false)
177-- Iteration 13 --
178
179Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
180bool(false)
181
182Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
183bool(false)
184-- Iteration 14 --
185
186Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
187bool(false)
188
189Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
190bool(false)
191-- Iteration 15 --
192
193Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
194bool(false)
195
196Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
197bool(false)
198-- Iteration 16 --
199
200Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
201bool(false)
202
203Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
204bool(false)
205-- Iteration 17 --
206
207Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
208bool(false)
209
210Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
211bool(false)
212-- Iteration 18 --
213
214Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
215bool(false)
216
217Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
218bool(false)
219-- Iteration 19 --
220
221Notice: Object of class sample could not be converted to int in %s on line %d
222
223Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
224bool(false)
225
226Notice: Object of class sample could not be converted to int in %s on line %d
227
228Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
229bool(false)
230-- Iteration 20 --
231bool(false)
232bool(false)
233-- Iteration 21 --
234bool(false)
235bool(false)
236-- Iteration 22 --
237
238Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
239bool(false)
240
241Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
242bool(false)
243-- Iteration 23 --
244
245Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
246bool(false)
247
248Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
249bool(false)
250-- Iteration 24 --
251
252Warning: strrpos() expects parameter 1 to be string, resource given in %s on line %d
253bool(false)
254
255Warning: strrpos() expects parameter 1 to be string, resource given in %s on line %d
256bool(false)
257-- Iteration 25 --
258
259Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
260bool(false)
261
262Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
263bool(false)
264-- Iteration 26 --
265
266Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
267bool(false)
268
269Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
270bool(false)
271*** Done ***
272