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