xref: /PHP-7.1/ext/mbstring/tests/bug43994.phpt (revision 113213f0)
1--TEST--
2Test mb_ereg() function : mb_ereg 'successfully' matching incorrectly
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
11 * Description: Regular expression match for multibyte string
12 * Source code: ext/mbstring/php_mbregex.c
13 */
14
15/*
16 * mb_ereg 'successfully' matching incorrectly:
17 * Bug now seems to be fixed - error message is now generated when an 'empty'
18 * pattern is supplied to mb_ereg. Similar error message to ereg().
19 */
20
21$unset_var = 10;
22unset ($unset_var);
23$inputs = array(NULL, null, false, FALSE, "", '', @$undefined_var,
24@$unset_var);
25
26$iterator = 1;
27foreach($inputs as $input) {
28	if(@is_array($mb_regs)){
29		$mb_regs = '';
30	}
31	echo "\n-- Iteration $iterator --\n";
32	echo "Without \$regs arg:\n";
33	var_dump( mb_ereg($input, 'hello, world') );
34	echo "With \$regs arg:\n";
35	var_dump(mb_ereg($input, 'hello, world', $mb_regs));
36	var_dump($mb_regs);
37	$iterator++;
38};
39?>
40--EXPECTF--
41-- Iteration 1 --
42Without $regs arg:
43
44Warning: mb_ereg(): empty pattern in %s on line %d
45bool(false)
46With $regs arg:
47
48Warning: mb_ereg(): empty pattern in %s on line %d
49bool(false)
50array(0) {
51}
52
53-- Iteration 2 --
54Without $regs arg:
55
56Warning: mb_ereg(): empty pattern in %s on line %d
57bool(false)
58With $regs arg:
59
60Warning: mb_ereg(): empty pattern in %s on line %d
61bool(false)
62array(0) {
63}
64
65-- Iteration 3 --
66Without $regs arg:
67
68Warning: mb_ereg(): empty pattern in %s on line %d
69bool(false)
70With $regs arg:
71
72Warning: mb_ereg(): empty pattern in %s on line %d
73bool(false)
74array(0) {
75}
76
77-- Iteration 4 --
78Without $regs arg:
79
80Warning: mb_ereg(): empty pattern in %s on line %d
81bool(false)
82With $regs arg:
83
84Warning: mb_ereg(): empty pattern in %s on line %d
85bool(false)
86array(0) {
87}
88
89-- Iteration 5 --
90Without $regs arg:
91
92Warning: mb_ereg(): empty pattern in %s on line %d
93bool(false)
94With $regs arg:
95
96Warning: mb_ereg(): empty pattern in %s on line %d
97bool(false)
98array(0) {
99}
100
101-- Iteration 6 --
102Without $regs arg:
103
104Warning: mb_ereg(): empty pattern in %s on line %d
105bool(false)
106With $regs arg:
107
108Warning: mb_ereg(): empty pattern in %s on line %d
109bool(false)
110array(0) {
111}
112
113-- Iteration 7 --
114Without $regs arg:
115
116Warning: mb_ereg(): empty pattern in %s on line %d
117bool(false)
118With $regs arg:
119
120Warning: mb_ereg(): empty pattern in %s on line %d
121bool(false)
122array(0) {
123}
124
125-- Iteration 8 --
126Without $regs arg:
127
128Warning: mb_ereg(): empty pattern in %s on line %d
129bool(false)
130With $regs arg:
131
132Warning: mb_ereg(): empty pattern in %s on line %d
133bool(false)
134array(0) {
135}
136