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