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