1--TEST--
2Test strrpos() function : usage variations - unexpected inputs for 'offset' argument
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 'offset' argument */
13
14echo "*** Testing strrpos() function: with unexpected values for 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//definition of input args
31$haystack = "hello world";
32$needle = "world";
33
34// array with different values
35$offsets =  array (
36
37  // float values
38  1.5,
39  -1.5,
40  1.5e10,
41  1.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 values
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($offsets); $index ++) {
82  echo "-- Iteration $counter --\n";
83  var_dump( strrpos($haystack, $needle, $offsets[$index]) );
84  $counter ++;
85}
86
87echo "*** Done ***";
88?>
89--EXPECTF--
90*** Testing strrpos() function: with unexpected values for offset ***
91-- Iteration 1 --
92int(6)
93-- Iteration 2 --
94int(6)
95-- Iteration 3 --
96
97Warning: strrpos() expects parameter 3 to be int, float given in %s on line %d
98bool(false)
99-- Iteration 4 --
100int(6)
101-- Iteration 5 --
102int(6)
103-- Iteration 6 --
104
105Warning: strrpos() expects parameter 3 to be int, array given in %s on line %d
106bool(false)
107-- Iteration 7 --
108
109Warning: strrpos() expects parameter 3 to be int, array given in %s on line %d
110bool(false)
111-- Iteration 8 --
112
113Warning: strrpos() expects parameter 3 to be int, array given in %s on line %d
114bool(false)
115-- Iteration 9 --
116
117Warning: strrpos() expects parameter 3 to be int, array given in %s on line %d
118bool(false)
119-- Iteration 10 --
120
121Warning: strrpos() expects parameter 3 to be int, array given in %s on line %d
122bool(false)
123-- Iteration 11 --
124int(6)
125-- Iteration 12 --
126int(6)
127-- Iteration 13 --
128int(6)
129-- Iteration 14 --
130int(6)
131-- Iteration 15 --
132
133Warning: strrpos() expects parameter 3 to be int, object given in %s on line %d
134bool(false)
135-- Iteration 16 --
136
137Warning: strrpos() expects parameter 3 to be int, string given in %s on line %d
138bool(false)
139-- Iteration 17 --
140
141Warning: strrpos() expects parameter 3 to be int, string given in %s on line %d
142bool(false)
143-- Iteration 18 --
144int(6)
145-- Iteration 19 --
146int(6)
147-- Iteration 20 --
148
149Warning: strrpos() expects parameter 3 to be int, resource given in %s on line %d
150bool(false)
151-- Iteration 21 --
152int(6)
153-- Iteration 22 --
154int(6)
155*** Done ***
156