xref: /PHP-8.1/ext/mbstring/tests/bug43994.phpt (revision 39131219)
1--TEST--
2Test mb_ereg() function : mb_ereg 'successfully' matching incorrectly
3--EXTENSIONS--
4mbstring
5--SKIPIF--
6<?php
7function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
8?>
9--FILE--
10<?php
11/*
12 * mb_ereg 'successfully' matching incorrectly:
13 * Bug now seems to be fixed - error message is now generated when an 'empty'
14 * pattern is supplied to mb_ereg. Similar error message to ereg().
15 */
16
17$inputs = array(false, FALSE, "", '');
18
19$iterator = 1;
20foreach($inputs as $input) {
21    if(@is_array($mb_regs)){
22        $mb_regs = '';
23    }
24    echo "\n-- Iteration $iterator --\n";
25    echo "Without \$regs arg:\n";
26    try {
27        var_dump( mb_ereg($input, 'hello, world') );
28    } catch (\ValueError $e) {
29        echo $e->getMessage() . \PHP_EOL;
30    }
31
32    echo "With \$regs arg:\n";
33    try {
34        var_dump(mb_ereg($input, 'hello, world', $mb_regs));
35    } catch (\ValueError $e) {
36        echo $e->getMessage() . \PHP_EOL;
37    }
38
39    var_dump($mb_regs);
40    $iterator++;
41};
42?>
43--EXPECT--
44-- Iteration 1 --
45Without $regs arg:
46mb_ereg(): Argument #1 ($pattern) must not be empty
47With $regs arg:
48mb_ereg(): Argument #1 ($pattern) must not be empty
49NULL
50
51-- Iteration 2 --
52Without $regs arg:
53mb_ereg(): Argument #1 ($pattern) must not be empty
54With $regs arg:
55mb_ereg(): Argument #1 ($pattern) must not be empty
56NULL
57
58-- Iteration 3 --
59Without $regs arg:
60mb_ereg(): Argument #1 ($pattern) must not be empty
61With $regs arg:
62mb_ereg(): Argument #1 ($pattern) must not be empty
63NULL
64
65-- Iteration 4 --
66Without $regs arg:
67mb_ereg(): Argument #1 ($pattern) must not be empty
68With $regs arg:
69mb_ereg(): Argument #1 ($pattern) must not be empty
70NULL
71