1--TEST--
2Test strrpos() function : usage variations - unexpected inputs for 'haystack', 'needle' & 'offset' 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', 'needle' & 'offset' arguments */
11
12echo "*** Testing strrpos() function: with unexpected values for haystack, needle & offset ***\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 vlaues
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  var_dump( strrpos($values[$index], $values[$index], $values[$index]) );
84  $counter ++;
85}
86
87echo "*** Done ***";
88?>
89--EXPECTF--
90*** Testing strrpos() function: with unexpected values for haystack, needle & offset ***
91-- Iteration 1 --
92bool(false)
93-- Iteration 2 --
94bool(false)
95-- Iteration 3 --
96
97Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
98bool(false)
99-- Iteration 4 --
100
101Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
102bool(false)
103-- Iteration 5 --
104
105Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
106bool(false)
107-- Iteration 6 --
108
109Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
110bool(false)
111-- Iteration 7 --
112
113Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
114bool(false)
115-- Iteration 8 --
116bool(false)
117-- Iteration 9 --
118bool(false)
119-- Iteration 10 --
120
121Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
122bool(false)
123-- Iteration 11 --
124
125Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
126bool(false)
127-- Iteration 12 --
128
129Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
130bool(false)
131-- Iteration 13 --
132
133Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
134bool(false)
135-- Iteration 14 --
136
137Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
138bool(false)
139-- Iteration 15 --
140bool(false)
141-- Iteration 16 --
142bool(false)
143-- Iteration 17 --
144bool(false)
145-- Iteration 18 --
146bool(false)
147-- Iteration 19 --
148
149Warning: strrpos() expects parameter 3 to be long, object given in %s on line %d
150bool(false)
151-- Iteration 20 --
152
153Warning: strrpos() expects parameter 3 to be long, string given in %s on line %d
154bool(false)
155-- Iteration 21 --
156
157Warning: strrpos() expects parameter 3 to be long, string given in %s on line %d
158bool(false)
159-- Iteration 22 --
160bool(false)
161-- Iteration 23 --
162bool(false)
163-- Iteration 24 --
164
165Warning: strrpos() expects parameter 1 to be string, resource given in %s on line %d
166bool(false)
167-- Iteration 25 --
168bool(false)
169-- Iteration 26 --
170bool(false)
171*** Done ***
172