1--TEST--
2Test mb_stripos() function : usage variations - pass different data types as $offset 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");
7if (PHP_INT_SIZE != 8) die('skip 64-bit only');
8?>
9--FILE--
10<?php
11/* Prototype  : int mb_stripos(string haystack, string needle [, int offset [, string encoding]])
12 * Description: Finds position of first 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_stripos different data types as $offset arg to test behaviour
19 */
20
21echo "*** Testing mb_stripos() : 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 "Class A object";
37  }
38}
39
40// heredoc string
41$heredoc = <<<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*/  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*/ "string",
80       '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_stripos()
97$iterator = 1;
98foreach($inputs as $input) {
99  echo "\n-- Iteration $iterator --\n";
100  var_dump( mb_stripos($haystack, $needle, $input, $encoding));
101  $iterator++;
102};
103
104fclose($fp);
105
106echo "Done";
107?>
108--EXPECTF--
109*** Testing mb_stripos() : usage variations ***
110
111-- Iteration 1 --
112int(8)
113
114-- Iteration 2 --
115int(8)
116
117-- Iteration 3 --
118
119Warning: mb_stripos(): Offset not contained in string in %s on line %d
120bool(false)
121
122-- Iteration 4 --
123
124Warning: mb_stripos(): Offset not contained in string in %s on line %d
125bool(false)
126
127-- Iteration 5 --
128bool(false)
129
130-- Iteration 6 --
131
132Warning: mb_stripos(): Offset not contained in string in %s on line %d
133bool(false)
134
135-- Iteration 7 --
136
137Warning: mb_stripos(): Offset not contained in string in %s on line %d
138bool(false)
139
140-- Iteration 8 --
141int(8)
142
143-- Iteration 9 --
144int(8)
145
146-- Iteration 10 --
147int(8)
148
149-- Iteration 11 --
150int(8)
151
152-- Iteration 12 --
153int(8)
154
155-- Iteration 13 --
156int(8)
157
158-- Iteration 14 --
159int(8)
160
161-- Iteration 15 --
162int(8)
163
164-- Iteration 16 --
165
166Warning: mb_stripos() expects parameter 3 to be integer, string given in %s on line %d
167NULL
168
169-- Iteration 17 --
170
171Warning: mb_stripos() expects parameter 3 to be integer, string given in %s on line %d
172NULL
173
174-- Iteration 18 --
175
176Warning: mb_stripos() expects parameter 3 to be integer, string given in %s on line %d
177NULL
178
179-- Iteration 19 --
180
181Warning: mb_stripos() expects parameter 3 to be integer, string given in %s on line %d
182NULL
183
184-- Iteration 20 --
185
186Warning: mb_stripos() expects parameter 3 to be integer, string given in %s on line %d
187NULL
188
189-- Iteration 21 --
190
191Warning: mb_stripos() expects parameter 3 to be integer, object given in %s on line %d
192NULL
193
194-- Iteration 22 --
195int(8)
196
197-- Iteration 23 --
198int(8)
199
200-- Iteration 24 --
201
202Warning: mb_stripos() expects parameter 3 to be integer, resource given in %s on line %d
203NULL
204Done
205