1--TEST--
2Test mb_strripos() 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_strripos($string_ascii, ''));
16
17echo "\n-- ASCII string with in range positive offset --\n";
18var_dump(mb_strripos($string_ascii, '', 2));
19
20echo "\n-- ASCII string with in range negative offset --\n";
21var_dump(mb_strripos($string_ascii, '', -2));
22
23echo "\n-- ASCII string with out of bound positive offset --\n";
24try {
25    var_dump(mb_strripos($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_strripos($string_ascii, '', -15));
33} catch (\ValueError $e) {
34    echo $e->getMessage() . \PHP_EOL;
35}
36
37
38echo "\n-- Multi-byte string without offset --\n";
39var_dump(mb_strripos($string_mb, ''));
40
41echo "\n-- Multi-byte string with in range positive offset --\n";
42var_dump(mb_strripos($string_mb, '', 2));
43
44echo "\n-- Multi-byte string with in range negative offset --\n";
45var_dump(mb_strripos($string_mb, '', -2));
46
47echo "\n-- Multi-byte string with out of bound positive offset --\n";
48try {
49    var_dump(mb_strripos($string_mb, '', 150));
50} catch (\ValueError $e) {
51    echo $e->getMessage() . \PHP_EOL;
52}
53
54echo "\n-- Multi-byte string with out of bound negative offset --\n";
55try {
56    var_dump(mb_strripos($string_mb, '', -150));
57} catch (\ValueError $e) {
58    echo $e->getMessage() . \PHP_EOL;
59}
60
61?>
62--EXPECT--
63-- ASCII string without offset --
64int(7)
65
66-- ASCII string with in range positive offset --
67int(7)
68
69-- ASCII string with in range negative offset --
70int(5)
71
72-- ASCII string with out of bound positive offset --
73mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
74
75-- ASCII string with out of bound negative offset --
76mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
77
78-- Multi-byte string without offset --
79int(21)
80
81-- Multi-byte string with in range positive offset --
82int(21)
83
84-- Multi-byte string with in range negative offset --
85int(19)
86
87-- Multi-byte string with out of bound positive offset --
88mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
89
90-- Multi-byte string with out of bound negative offset --
91mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
92