1--TEST--
2Test mb_strpos() function : with empty needle
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7
8mb_internal_encoding('UTF-8');
9
10$string_ascii = 'abc def';
11// Japanese string in UTF-8
12$string_mb = "日本語テキストです。0123456789。";
13
14echo "\n-- ASCII string without offset --\n";
15var_dump(mb_strpos($string_ascii, ''));
16
17echo "\n-- ASCII string with in range positive offset --\n";
18var_dump(mb_strpos($string_ascii, '', 2));
19
20echo "\n-- ASCII string with in range negative offset --\n";
21var_dump(mb_strpos($string_ascii, '', -2));
22
23echo "\n-- ASCII string with out of bound positive offset --\n";
24try {
25    var_dump(mb_strpos($string_ascii, '', 15));
26} catch (\ValueError $e) {
27    echo $e->getMessage() . \PHP_EOL;
28}
29
30echo "\n-- ASCII string with out of bound negative offset --\n";
31try {
32    var_dump(mb_strpos($string_ascii, '', -15));
33} catch (\ValueError $e) {
34    echo $e->getMessage() . \PHP_EOL;
35}
36
37echo "\n-- Multi-byte string without offset --\n";
38var_dump(mb_strpos($string_mb, ''));
39
40echo "\n-- Multi-byte string with in range positive offset --\n";
41var_dump(mb_strpos($string_mb, '', 2));
42
43echo "\n-- Multi-byte string with in range negative offset --\n";
44var_dump(mb_strpos($string_mb, '', -2));
45
46echo "\n-- Multi-byte string with out of bound positive offset --\n";
47try {
48    var_dump(mb_strpos($string_mb, '', 150));
49} catch (\ValueError $e) {
50    echo $e->getMessage() . \PHP_EOL;
51}
52
53echo "\n-- Multi-byte string with out of bound negative offset --\n";
54try {
55    var_dump(mb_strpos($string_mb, '', -150));
56} catch (\ValueError $e) {
57    echo $e->getMessage() . \PHP_EOL;
58}
59
60?>
61--EXPECT--
62-- ASCII string without offset --
63int(0)
64
65-- ASCII string with in range positive offset --
66int(2)
67
68-- ASCII string with in range negative offset --
69int(5)
70
71-- ASCII string with out of bound positive offset --
72mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
73
74-- ASCII string with out of bound negative offset --
75mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
76
77-- Multi-byte string without offset --
78int(0)
79
80-- Multi-byte string with in range positive offset --
81int(2)
82
83-- Multi-byte string with in range negative offset --
84int(19)
85
86-- Multi-byte string with out of bound positive offset --
87mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
88
89-- Multi-byte string with out of bound negative offset --
90mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
91