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