1--TEST--
2mb_strpos() with invalid offsets
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7
8ini_set('include_path','.');
9include_once('common.inc');
10mb_internal_encoding('UTF-8') or print("mb_internal_encoding() failed\n");
11
12// Test string
13$string = '0123この文字列は日本語です。UTF-8を使っています。0123日本語は面倒臭い。';
14
15$slen = mb_strlen($string);
16echo "String len: $slen\n";
17
18print ("== INVALID OFFSET ==\n");
19
20try {
21    var_dump( mb_strpos($string, '日本語', 44));
22} catch (\ValueError $e) {
23    echo $e->getMessage() . \PHP_EOL;
24}
25
26try {
27    var_dump( mb_strpos($string, '日本語', 50));
28} catch (\ValueError $e) {
29    echo $e->getMessage() . \PHP_EOL;
30}
31
32try {
33    var_dump( mb_strpos($string, '0', 50));
34} catch (\ValueError $e) {
35    echo $e->getMessage() . \PHP_EOL;
36}
37
38try {
39    var_dump(mb_strpos($string, 3, 50));
40} catch (\ValueError $e) {
41    echo $e->getMessage() . \PHP_EOL;
42}
43
44try {
45    var_dump(mb_strpos($string, 0, 50));
46} catch (\ValueError $e) {
47    echo $e->getMessage() . \PHP_EOL;
48}
49
50try {
51    var_dump(mb_strpos($string, '日本語', -50));
52} catch (\ValueError $e) {
53    echo $e->getMessage() . \PHP_EOL;
54}
55
56try {
57    var_dump(mb_strpos($string, '0', -50));
58} catch (\ValueError $e) {
59    echo $e->getMessage() . \PHP_EOL;
60}
61
62try {
63    var_dump(mb_strpos($string, 3, -50));
64} catch (\ValueError $e) {
65    echo $e->getMessage() . \PHP_EOL;
66}
67
68try {
69    var_dump(mb_strpos($string, 0, -50));
70} catch (\ValueError $e) {
71    echo $e->getMessage() . \PHP_EOL;
72}
73
74try {
75    var_dump(mb_strpos($string, 0, -44));
76} catch (\ValueError $e) {
77    echo $e->getMessage() . \PHP_EOL;
78}
79
80?>
81--EXPECT--
82String len: 42
83== INVALID OFFSET ==
84mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
85mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
86mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
87mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
88mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
89mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
90mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
91mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
92mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
93mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
94