1--TEST--
2Test mb_strripos() function : usage variations - pass different data types as $encoding 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 $encoding arg to test behaviour
18 * Where possible 'UTF-8' has been entered as a string value
19 */
20
21echo "*** Testing mb_strripos() : usage variations ***\n";
22
23// Initialise function arguments not being substituted
24$haystack = b'string_val';
25$needle = b'VaL';
26$offset = 0;
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 "UTF-8";
37  }
38}
39
40// heredoc string
41$heredoc = <<<EOT
42UTF-8
43EOT;
44
45// get a resource variable
46$fp = fopen(__FILE__, "r");
47
48// unexpected values to be passed to $input argument
49$inputs = array(
50
51       // int data
52/*1*/  0,
53       1,
54       12345,
55       -2345,
56
57       // float data
58/*5*/  10.5,
59       -10.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*/ "UTF-8",
80       'UTF-8',
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, $offset, $input));
101  $iterator++;
102};
103
104fclose($fp);
105
106echo "Done";
107?>
108
109--EXPECTF--
110*** Testing mb_strripos() : usage variations ***
111
112-- Iteration 1 --
113
114Warning: mb_strripos(): Unknown encoding "0" in %s on line %d
115bool(false)
116
117-- Iteration 2 --
118
119Warning: mb_strripos(): Unknown encoding "1" in %s on line %d
120bool(false)
121
122-- Iteration 3 --
123
124Warning: mb_strripos(): Unknown encoding "12345" in %s on line %d
125bool(false)
126
127-- Iteration 4 --
128
129Warning: mb_strripos(): Unknown encoding "-2345" in %s on line %d
130bool(false)
131
132-- Iteration 5 --
133
134Warning: mb_strripos(): Unknown encoding "10.5" in %s on line %d
135bool(false)
136
137-- Iteration 6 --
138
139Warning: mb_strripos(): Unknown encoding "-10.5" in %s on line %d
140bool(false)
141
142-- Iteration 7 --
143
144Warning: mb_strripos(): Unknown encoding "123456789000" in %s on line %d
145bool(false)
146
147-- Iteration 8 --
148
149Warning: mb_strripos(): Unknown encoding "1.23456789E-9" in %s on line %d
150bool(false)
151
152-- Iteration 9 --
153
154Warning: mb_strripos(): Unknown encoding "0.5" in %s on line %d
155bool(false)
156
157-- Iteration 10 --
158
159Warning: mb_strripos(): Unknown encoding "" in %s on line %d
160bool(false)
161
162-- Iteration 11 --
163
164Warning: mb_strripos(): Unknown encoding "" in %s on line %d
165bool(false)
166
167-- Iteration 12 --
168
169Warning: mb_strripos(): Unknown encoding "1" in %s on line %d
170bool(false)
171
172-- Iteration 13 --
173
174Warning: mb_strripos(): Unknown encoding "" in %s on line %d
175bool(false)
176
177-- Iteration 14 --
178
179Warning: mb_strripos(): Unknown encoding "1" in %s on line %d
180bool(false)
181
182-- Iteration 15 --
183
184Warning: mb_strripos(): Unknown encoding "" in %s on line %d
185bool(false)
186
187-- Iteration 16 --
188
189Warning: mb_strripos(): Unknown encoding "" in %s on line %d
190bool(false)
191
192-- Iteration 17 --
193
194Warning: mb_strripos(): Unknown encoding "" in %s on line %d
195bool(false)
196
197-- Iteration 18 --
198int(7)
199
200-- Iteration 19 --
201int(7)
202
203-- Iteration 20 --
204int(7)
205
206-- Iteration 21 --
207int(7)
208
209-- Iteration 22 --
210
211Warning: mb_strripos(): Unknown encoding "" in %s on line %d
212bool(false)
213
214-- Iteration 23 --
215
216Warning: mb_strripos(): Unknown encoding "" in %s on line %d
217bool(false)
218
219-- Iteration 24 --
220
221Warning: mb_strripos() expects parameter 4 to be string, resource given in %s on line %d
222bool(false)
223Done