1--TEST--
2Test mb_strripos() function : usage variations - pass different data types as $offset arg
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_strripos') or die("skip mb_strripos() is not available in this build");
7if (PHP_INT_SIZE != 8) die('skip 64-bit only');
8?>
9--FILE--
10<?php
11/* Prototype  : int mb_strripos(string haystack, string needle [, int offset [, string encoding]])
12 * Description: Finds position of last occurrence of a string within another, case insensitive
13 * Source code: ext/mbstring/mbstring.c
14 * Alias to functions:
15 */
16
17/*
18 * Pass mb_strripos different data types as $offset arg to test behaviour
19 */
20
21echo "*** Testing mb_strripos() : usage variations ***\n";
22
23// Initialise function arguments not being substituted
24$needle = b'A';
25$haystack = b'string_val';
26$encoding = 'utf-8';
27
28//get an unset variable
29$unset_var = 10;
30unset ($unset_var);
31
32// get a class
33class classA
34{
35  public function __toString() {
36    return b"Class A object";
37  }
38}
39
40// heredoc string
41$heredoc = b<<<EOT
42hello world
43EOT;
44
45// get a resource variable
46$fp = fopen(__FILE__, "r");
47
48// unexpected values to be passed to $offest argument
49$inputs = array(
50
51       // int data
52/*1*/  0,
53       1,
54       12345,
55       -2345,
56
57       // float data
58/*5*/  12.5,
59       -12.5,
60       12.3456789000e10,
61       12.3456789000E-10,
62       .5,
63
64       // null data
65/*10*/ NULL,
66       null,
67
68       // boolean data
69/*12*/ true,
70       false,
71       TRUE,
72       FALSE,
73
74       // empty data
75/*16*/ "",
76       '',
77
78       // string data
79/*18*/ b"string",
80       b'string',
81       $heredoc,
82
83       // object data
84/*21*/ new classA(),
85
86       // undefined data
87/*22*/ @$undefined_var,
88
89       // unset data
90/*23*/ @$unset_var,
91
92       // resource variable
93/*24*/ $fp
94);
95
96// loop through each element of $inputs to check the behavior of mb_strripos()
97$iterator = 1;
98foreach($inputs as $input) {
99  echo "\n-- Iteration $iterator --\n";
100  var_dump( mb_strripos($haystack, $needle, $input, $encoding));
101  $iterator++;
102};
103
104fclose($fp);
105
106echo "Done";
107?>
108--EXPECTF--
109*** Testing mb_strripos() : usage variations ***
110
111-- Iteration 1 --
112int(8)
113
114-- Iteration 2 --
115int(8)
116
117-- Iteration 3 --
118
119Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
120bool(false)
121
122-- Iteration 4 --
123
124Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
125bool(false)
126
127-- Iteration 5 --
128
129Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
130bool(false)
131
132-- Iteration 6 --
133
134Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
135bool(false)
136
137-- Iteration 7 --
138
139Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
140bool(false)
141
142-- Iteration 8 --
143int(8)
144
145-- Iteration 9 --
146int(8)
147
148-- Iteration 10 --
149int(8)
150
151-- Iteration 11 --
152int(8)
153
154-- Iteration 12 --
155int(8)
156
157-- Iteration 13 --
158int(8)
159
160-- Iteration 14 --
161int(8)
162
163-- Iteration 15 --
164int(8)
165
166-- Iteration 16 --
167
168Warning: mb_strripos() expects parameter 3 to be integer, string given in %s on line %d
169NULL
170
171-- Iteration 17 --
172
173Warning: mb_strripos() expects parameter 3 to be integer, string given in %s on line %d
174NULL
175
176-- Iteration 18 --
177
178Warning: mb_strripos() expects parameter 3 to be integer, string given in %s on line %d
179NULL
180
181-- Iteration 19 --
182
183Warning: mb_strripos() expects parameter 3 to be integer, string given in %s on line %d
184NULL
185
186-- Iteration 20 --
187
188Warning: mb_strripos() expects parameter 3 to be integer, string given in %s on line %d
189NULL
190
191-- Iteration 21 --
192
193Warning: mb_strripos() expects parameter 3 to be integer, object given in %s on line %d
194NULL
195
196-- Iteration 22 --
197int(8)
198
199-- Iteration 23 --
200int(8)
201
202-- Iteration 24 --
203
204Warning: mb_strripos() expects parameter 3 to be integer, resource given in %s on line %d
205NULL
206Done
207
208