1--TEST--
2Test mb_strpos() function : usage variations - Pass different integers as $offset argument
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");
7?>
8--FILE--
9<?php
10/*
11 * Test how mb_strpos() behaves when passed different integers as $offset argument
12 * The character length of $string_ascii and $string_mb is the same,
13 * and the needle appears at the same positions in both strings
14 */
15
16mb_internal_encoding('UTF-8');
17
18echo "*** Testing mb_strpos() : usage variations ***\n";
19
20$string_ascii = '+Is an English string'; //21 chars
21$needle_ascii = 'g';
22
23$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
24$needle_mb = base64_decode('44CC');
25
26/*
27 * Loop through integers as multiples of ten for $offset argument
28 * 60 is larger than *BYTE* count for $string_mb
29 */
30for ($i = -30; $i <= 60; $i += 10) {
31    echo "\n**-- Offset is: $i --**\n";
32    echo "-- ASCII String --\n";
33    try {
34        var_dump(mb_strpos($string_ascii, $needle_ascii, $i));
35    } catch (\ValueError $e) {
36        echo $e->getMessage() . \PHP_EOL;
37    }
38
39    echo "--Multibyte String --\n";
40    try {
41        var_dump(mb_strpos($string_mb, $needle_mb, $i, 'UTF-8'));
42    } catch (\ValueError $e) {
43        echo $e->getMessage() . \PHP_EOL;
44    }
45}
46
47?>
48--EXPECT--
49*** Testing mb_strpos() : usage variations ***
50
51**-- Offset is: -30 --**
52-- ASCII String --
53mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
54--Multibyte String --
55mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
56
57**-- Offset is: -20 --**
58-- ASCII String --
59int(9)
60--Multibyte String --
61int(9)
62
63**-- Offset is: -10 --**
64-- ASCII String --
65int(20)
66--Multibyte String --
67int(20)
68
69**-- Offset is: 0 --**
70-- ASCII String --
71int(9)
72--Multibyte String --
73int(9)
74
75**-- Offset is: 10 --**
76-- ASCII String --
77int(20)
78--Multibyte String --
79int(20)
80
81**-- Offset is: 20 --**
82-- ASCII String --
83int(20)
84--Multibyte String --
85int(20)
86
87**-- Offset is: 30 --**
88-- ASCII String --
89mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
90--Multibyte String --
91mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
92
93**-- Offset is: 40 --**
94-- ASCII String --
95mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
96--Multibyte String --
97mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
98
99**-- Offset is: 50 --**
100-- ASCII String --
101mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
102--Multibyte String --
103mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
104
105**-- Offset is: 60 --**
106-- ASCII String --
107mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
108--Multibyte String --
109mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
110