1--TEST--
2Test mb_stripos() function : usage variations - pass different data types as $encoding arg
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : int mb_stripos(string haystack, string needle [, int offset [, string encoding]])
11 * Description: Finds position of first 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_stripos 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_stripos() : 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_stripos()
97$iterator = 1;
98foreach($inputs as $input) {
99  echo "\n-- Iteration $iterator --\n";
100  var_dump( mb_stripos($haystack, $needle, $offset, $input));
101  $iterator++;
102};
103
104fclose($fp);
105
106echo "Done";
107?>
108--EXPECTF--
109*** Testing mb_stripos() : usage variations ***
110
111-- Iteration 1 --
112
113Warning: mb_stripos(): Unknown encoding "0" in %s on line %d
114bool(false)
115
116-- Iteration 2 --
117
118Warning: mb_stripos(): Unknown encoding "1" in %s on line %d
119bool(false)
120
121-- Iteration 3 --
122
123Warning: mb_stripos(): Unknown encoding "12345" in %s on line %d
124bool(false)
125
126-- Iteration 4 --
127
128Warning: mb_stripos(): Unknown encoding "-2345" in %s on line %d
129bool(false)
130
131-- Iteration 5 --
132
133Warning: mb_stripos(): Unknown encoding "10.5" in %s on line %d
134bool(false)
135
136-- Iteration 6 --
137
138Warning: mb_stripos(): Unknown encoding "-10.5" in %s on line %d
139bool(false)
140
141-- Iteration 7 --
142
143Warning: mb_stripos(): Unknown encoding "123456789000" in %s on line %d
144bool(false)
145
146-- Iteration 8 --
147
148Warning: mb_stripos(): Unknown encoding "1.23456789E-9" in %s on line %d
149bool(false)
150
151-- Iteration 9 --
152
153Warning: mb_stripos(): Unknown encoding "0.5" in %s on line %d
154bool(false)
155
156-- Iteration 10 --
157
158Warning: mb_stripos(): Unknown encoding "" in %s on line %d
159bool(false)
160
161-- Iteration 11 --
162
163Warning: mb_stripos(): Unknown encoding "" in %s on line %d
164bool(false)
165
166-- Iteration 12 --
167
168Warning: mb_stripos(): Unknown encoding "1" in %s on line %d
169bool(false)
170
171-- Iteration 13 --
172
173Warning: mb_stripos(): Unknown encoding "" in %s on line %d
174bool(false)
175
176-- Iteration 14 --
177
178Warning: mb_stripos(): Unknown encoding "1" in %s on line %d
179bool(false)
180
181-- Iteration 15 --
182
183Warning: mb_stripos(): Unknown encoding "" in %s on line %d
184bool(false)
185
186-- Iteration 16 --
187
188Warning: mb_stripos(): Unknown encoding "" in %s on line %d
189bool(false)
190
191-- Iteration 17 --
192
193Warning: mb_stripos(): Unknown encoding "" in %s on line %d
194bool(false)
195
196-- Iteration 18 --
197int(7)
198
199-- Iteration 19 --
200int(7)
201
202-- Iteration 20 --
203int(7)
204
205-- Iteration 21 --
206int(7)
207
208-- Iteration 22 --
209
210Warning: mb_stripos(): Unknown encoding "" in %s on line %d
211bool(false)
212
213-- Iteration 23 --
214
215Warning: mb_stripos(): Unknown encoding "" in %s on line %d
216bool(false)
217
218-- Iteration 24 --
219
220Warning: mb_stripos() expects parameter 4 to be string, resource given in %s on line %d
221NULL
222Done
223