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