1--TEST--
2Test strrpos() function : usage variations - unexpected inputs for 'haystack', 'needle' & 'offset' arguments
3--SKIPIF--
4<?php if (PHP_INT_SIZE !== 4) die("skip this test is for 32-bit only");
5--FILE--
6<?php
7/* Prototype  : int strrpos ( string $haystack, string $needle [, int $offset] );
8 * Description: Find position of last occurrence of 'needle' in 'haystack'.
9 * Source code: ext/standard/string.c
10*/
11
12/* Test strrpos() function with unexpected inputs for 'haystack', 'needle' & 'offset' arguments */
13
14echo "*** Testing strrpos() function: with unexpected values for haystack, needle & offset ***\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// array with different values
31$values =  array (
32
33  // integer values
34  0,
35  1,
36  12345,
37  -2345,
38
39  // float values
40  10.5,
41  -10.5,
42  10.5e10,
43  10.6E-10,
44  .5,
45
46  // array values
47  array(),
48  array(0),
49  array(1),
50  array(1, 2),
51  array('color' => 'red', 'item' => 'pen'),
52
53  // boolean values
54  true,
55  false,
56  TRUE,
57  FALSE,
58
59  // objects
60  new sample(),
61
62  // empty string
63  "",
64  '',
65
66  // null vlaues
67  NULL,
68  null,
69
70  //resource
71  $file_handle,
72
73  // undefined variable
74  @$undefined_var,
75
76  // unset variable
77  @$unset_var
78);
79
80
81// loop through each element of the array and check the working of strrpos()
82$counter = 1;
83for($index = 0; $index < count($values); $index ++) {
84  echo "-- Iteration $counter --\n";
85  var_dump( strrpos($values[$index], $values[$index], $values[$index]) );
86  $counter ++;
87}
88
89echo "*** Done ***";
90?>
91--EXPECTF--
92*** Testing strrpos() function: with unexpected values for haystack, needle & offset ***
93-- Iteration 1 --
94bool(false)
95-- Iteration 2 --
96bool(false)
97-- Iteration 3 --
98
99Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
100bool(false)
101-- Iteration 4 --
102
103Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
104bool(false)
105-- Iteration 5 --
106
107Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
108bool(false)
109-- Iteration 6 --
110
111Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
112bool(false)
113-- Iteration 7 --
114
115Warning: strrpos() expects parameter 3 to be integer, float given in %s on line %d
116bool(false)
117-- Iteration 8 --
118bool(false)
119-- Iteration 9 --
120bool(false)
121-- Iteration 10 --
122
123Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
124bool(false)
125-- Iteration 11 --
126
127Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
128bool(false)
129-- Iteration 12 --
130
131Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
132bool(false)
133-- Iteration 13 --
134
135Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
136bool(false)
137-- Iteration 14 --
138
139Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
140bool(false)
141-- Iteration 15 --
142bool(false)
143-- Iteration 16 --
144bool(false)
145-- Iteration 17 --
146bool(false)
147-- Iteration 18 --
148bool(false)
149-- Iteration 19 --
150
151Warning: strrpos() expects parameter 3 to be integer, object given in %s on line %d
152bool(false)
153-- Iteration 20 --
154
155Warning: strrpos() expects parameter 3 to be integer, string given in %s on line %d
156bool(false)
157-- Iteration 21 --
158
159Warning: strrpos() expects parameter 3 to be integer, string given in %s on line %d
160bool(false)
161-- Iteration 22 --
162bool(false)
163-- Iteration 23 --
164bool(false)
165-- Iteration 24 --
166
167Warning: strrpos() expects parameter 1 to be string, resource given in %s on line %d
168bool(false)
169-- Iteration 25 --
170bool(false)
171-- Iteration 26 --
172bool(false)
173*** Done ***
174