1--TEST--
2Test mb_strpos() function : usage variations - pass different data types as $offset arg
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_strpos') or die("skip mb_strpos() 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_strpos(string $haystack, string $needle [, int $offset [, string $encoding]])
12 * Description: Find position of first occurrence of a string within another
13 * Source code: ext/mbstring/mbstring.c
14 */
15
16/*
17 * Pass mb_strpos different data types as $offset arg to test behaviour
18 */
19
20echo "*** Testing mb_strpos() : usage variations ***\n";
21
22// Initialise function arguments not being substituted
23$needle = 'a';
24$haystack = '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 "Class A object";
36  }
37}
38
39// heredoc string
40$heredoc = <<<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	   -5,
55       -2345,
56
57       // float data
58/*6*/  10.5,
59       -5.5,
60	   -100.5,
61       12.3456789000e10,
62       12.3456789000E-10,
63       .5,
64
65       // null data
66/*12*/ NULL,
67       null,
68
69       // boolean data
70/*14*/ true,
71       false,
72       TRUE,
73       FALSE,
74
75       // empty data
76/*18*/ "",
77       '',
78
79       // string data
80/*20*/ "string",
81       'string',
82       $heredoc,
83
84       // object data
85/*23*/ new classA(),
86
87       // undefined data
88/*24*/ @$undefined_var,
89
90       // unset data
91/*25*/ @$unset_var,
92
93       // resource variable
94/*26*/ $fp
95);
96
97// loop through each element of $inputs to check the behavior of mb_strpos()
98$iterator = 1;
99foreach($inputs as $input) {
100  echo "\n-- Iteration $iterator --\n";
101  var_dump( mb_strpos($haystack, $needle, $input, $encoding));
102  $iterator++;
103};
104
105fclose($fp);
106
107echo "Done";
108?>
109--EXPECTF--
110*** Testing mb_strpos() : usage variations ***
111
112-- Iteration 1 --
113int(8)
114
115-- Iteration 2 --
116int(8)
117
118-- Iteration 3 --
119
120Warning: mb_strpos(): Offset not contained in string in %s on line %d
121bool(false)
122
123-- Iteration 4 --
124int(8)
125
126-- Iteration 5 --
127
128Warning: mb_strpos(): Offset not contained in string in %s on line %d
129bool(false)
130
131-- Iteration 6 --
132bool(false)
133
134-- Iteration 7 --
135int(8)
136
137-- Iteration 8 --
138
139Warning: mb_strpos(): Offset not contained in string in %s on line %d
140bool(false)
141
142-- Iteration 9 --
143
144Warning: mb_strpos(): Offset not contained in string in %s on line %d
145bool(false)
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 --
166int(8)
167
168-- Iteration 17 --
169int(8)
170
171-- Iteration 18 --
172
173Warning: mb_strpos() expects parameter 3 to be integer, string given in %s on line %d
174NULL
175
176-- Iteration 19 --
177
178Warning: mb_strpos() expects parameter 3 to be integer, string given in %s on line %d
179NULL
180
181-- Iteration 20 --
182
183Warning: mb_strpos() expects parameter 3 to be integer, string given in %s on line %d
184NULL
185
186-- Iteration 21 --
187
188Warning: mb_strpos() expects parameter 3 to be integer, string given in %s on line %d
189NULL
190
191-- Iteration 22 --
192
193Warning: mb_strpos() expects parameter 3 to be integer, string given in %s on line %d
194NULL
195
196-- Iteration 23 --
197
198Warning: mb_strpos() expects parameter 3 to be integer, object given in %s on line %d
199NULL
200
201-- Iteration 24 --
202int(8)
203
204-- Iteration 25 --
205int(8)
206
207-- Iteration 26 --
208
209Warning: mb_strpos() expects parameter 3 to be integer, resource given in %s on line %d
210NULL
211Done
212