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