1--TEST--
2Test strrpos() function : usage variations - unexpected inputs for 'needle' argument
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 'needle' and
11 *  an expected type of input for 'haystack' argument
12*/
13
14echo "*** Testing strrpos() 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 strrpos()
83$counter = 1;
84for($index = 0; $index < count($needles); $index ++) {
85  echo "-- Iteration $counter --\n";
86  var_dump( strrpos($haystack, $needles[$index]) );
87  $counter ++;
88}
89
90fclose($file_handle);  //closing the file handle
91
92echo "*** Done ***";
93?>
94--EXPECTF--
95*** Testing strrpos() function with unexpected values for needle ***
96-- Iteration 1 --
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-- Iteration 3 --
105
106Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
107bool(false)
108-- Iteration 4 --
109
110Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
111bool(false)
112-- Iteration 5 --
113
114Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
115bool(false)
116-- Iteration 6 --
117
118Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
119bool(false)
120-- Iteration 7 --
121
122Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
123bool(false)
124-- Iteration 8 --
125
126Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
127bool(false)
128-- Iteration 9 --
129
130Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
131bool(false)
132-- Iteration 10 --
133
134Warning: strrpos(): needle is not a string or an integer in %s on line %d
135bool(false)
136-- Iteration 11 --
137
138Warning: strrpos(): needle is not a string or an integer in %s on line %d
139bool(false)
140-- Iteration 12 --
141
142Warning: strrpos(): needle is not a string or an integer in %s on line %d
143bool(false)
144-- Iteration 13 --
145
146Warning: strrpos(): needle is not a string or an integer in %s on line %d
147bool(false)
148-- Iteration 14 --
149
150Warning: strrpos(): needle is not a string or an integer in %s on line %d
151bool(false)
152-- Iteration 15 --
153
154Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
155bool(false)
156-- Iteration 16 --
157
158Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
159bool(false)
160-- Iteration 17 --
161
162Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
163bool(false)
164-- Iteration 18 --
165
166Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
167bool(false)
168-- Iteration 19 --
169
170Notice: Object of class sample could not be converted to int in %s on line %d
171
172Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
173bool(false)
174-- Iteration 20 --
175bool(false)
176-- Iteration 21 --
177bool(false)
178-- Iteration 22 --
179
180Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
181bool(false)
182-- Iteration 23 --
183
184Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
185bool(false)
186-- Iteration 24 --
187
188Warning: strrpos(): needle is not a string or an integer in %s on line %d
189bool(false)
190-- Iteration 25 --
191
192Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
193bool(false)
194-- Iteration 26 --
195
196Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
197bool(false)
198*** Done ***
199