1--TEST--
2Test mb_strripos() function : usage variations - Pass different integers as $offset argument
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/*
11 * Test how mb_strripos() behaves when passed different integers as $offset argument
12 * The character length of $string_ascii and $string_mb is the same,
13 * and the needle appears at the same positions in both strings
14 */
15
16mb_internal_encoding('UTF-8');
17
18echo "*** Testing mb_strripos() : usage variations ***\n";
19
20$string_ascii = '+Is an English string'; //21 chars
21$needle_ascii = 'G';
22
23$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
24$needle_mb = base64_decode('44CC');
25
26/*
27 * Loop through integers as multiples of ten for $offset argument
28 * mb_strripos should not be able to accept negative values as $offset.
29 * 60 is larger than *BYTE* count for $string_mb
30 */
31for ($i = -10; $i <= 60; $i += 10) {
32    echo "\n**-- Offset is: $i --**\n";
33    echo "-- ASCII String --\n";
34    try {
35        var_dump(mb_strripos($string_ascii, $needle_ascii, $i));
36    } catch (\ValueError $e) {
37        echo $e->getMessage() . \PHP_EOL;
38    }
39
40    echo "--Multibyte String --\n";
41    try {
42        var_dump(mb_strripos($string_mb, $needle_mb, $i, 'UTF-8'));
43    } catch (\ValueError $e) {
44        echo $e->getMessage() . \PHP_EOL;
45    }
46}
47
48?>
49--EXPECT--
50*** Testing mb_strripos() : usage variations ***
51
52**-- Offset is: -10 --**
53-- ASCII String --
54int(9)
55--Multibyte String --
56int(9)
57
58**-- Offset is: 0 --**
59-- ASCII String --
60int(20)
61--Multibyte String --
62int(20)
63
64**-- Offset is: 10 --**
65-- ASCII String --
66int(20)
67--Multibyte String --
68int(20)
69
70**-- Offset is: 20 --**
71-- ASCII String --
72int(20)
73--Multibyte String --
74int(20)
75
76**-- Offset is: 30 --**
77-- ASCII String --
78mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
79--Multibyte String --
80mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
81
82**-- Offset is: 40 --**
83-- ASCII String --
84mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
85--Multibyte String --
86mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
87
88**-- Offset is: 50 --**
89-- ASCII String --
90mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
91--Multibyte String --
92mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
93
94**-- Offset is: 60 --**
95-- ASCII String --
96mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
97--Multibyte String --
98mb_strripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
99