1--TEST--
2Test strrpos() function : usage variations - unexpected inputs for 'needle' argument
3--FILE--
4<?php
5/* Test strrpos() function with unexpected inputs for 'needle' and
6 *  an expected type of input for 'haystack' argument
7*/
8
9echo "*** Testing strrpos() function with unexpected values for needle ***\n";
10
11//get an unset variable
12$unset_var = 'string_val';
13unset($unset_var);
14
15//defining a class
16class sample  {
17  public function __toString() {
18    return "object";
19  }
20}
21
22//getting the resource
23$file_handle = fopen(__FILE__, "r");
24
25$haystack = "string 0 1 2 -2 10.5 -10.5 10.5e10 10.6E-10 .5 array true false object \"\" null Resource";
26
27// array with different values
28$needles =  array (
29
30  // integer values
31  0,
32  1,
33  12345,
34  -2345,
35
36  // float values
37  10.5,
38  -10.5,
39  10.1234567e10,
40  10.7654321E-10,
41  .5,
42
43  // array values
44  array(),
45  array(0),
46  array(1),
47  array(1, 2),
48  array('color' => 'red', 'item' => 'pen'),
49
50  // boolean values
51  true,
52  false,
53  TRUE,
54  FALSE,
55
56  // objects
57  new sample(),
58
59  // empty string
60  "",
61  '',
62
63  // null values
64  NULL,
65  null,
66
67  // resource
68  $file_handle,
69
70  // undefined variable
71  @$undefined_var,
72
73  // unset variable
74  @$unset_var
75);
76
77// loop through each element of the 'needle' array to check the working of strrpos()
78$counter = 1;
79for($index = 0; $index < count($needles); $index ++) {
80  echo "-- Iteration $counter --\n";
81  try {
82    var_dump( strrpos($haystack, $needles[$index]) );
83  } catch (TypeError $e) {
84    echo $e->getMessage(), "\n";
85  }
86  $counter ++;
87}
88
89fclose($file_handle);  //closing the file handle
90
91echo "*** Done ***";
92?>
93--EXPECT--
94*** Testing strrpos() function with unexpected values for needle ***
95-- Iteration 1 --
96int(42)
97-- Iteration 2 --
98int(41)
99-- Iteration 3 --
100bool(false)
101-- Iteration 4 --
102bool(false)
103-- Iteration 5 --
104int(27)
105-- Iteration 6 --
106int(21)
107-- Iteration 7 --
108bool(false)
109-- Iteration 8 --
110bool(false)
111-- Iteration 9 --
112int(28)
113-- Iteration 10 --
114strrpos(): Argument #2 ($needle) must be of type string, array given
115-- Iteration 11 --
116strrpos(): Argument #2 ($needle) must be of type string, array given
117-- Iteration 12 --
118strrpos(): Argument #2 ($needle) must be of type string, array given
119-- Iteration 13 --
120strrpos(): Argument #2 ($needle) must be of type string, array given
121-- Iteration 14 --
122strrpos(): Argument #2 ($needle) must be of type string, array given
123-- Iteration 15 --
124int(41)
125-- Iteration 16 --
126int(87)
127-- Iteration 17 --
128int(41)
129-- Iteration 18 --
130int(87)
131-- Iteration 19 --
132int(64)
133-- Iteration 20 --
134int(87)
135-- Iteration 21 --
136int(87)
137-- Iteration 22 --
138int(87)
139-- Iteration 23 --
140int(87)
141-- Iteration 24 --
142strrpos(): Argument #2 ($needle) must be of type string, resource given
143-- Iteration 25 --
144int(87)
145-- Iteration 26 --
146int(87)
147*** Done ***
148