1--TEST--
2Test mb_ereg() function : usage variations - pass different data types to $string arg
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 * Test behaviour of mb_ereg() when passed different data types as $string arg
17 */
18
19echo "*** Testing mb_ereg() : usage variations ***\n";
20
21// Initialise function arguments not being substituted
22$pattern = 'str';
23
24//get an unset variable
25$unset_var = 10;
26unset ($unset_var);
27
28// get a class
29class classA
30{
31	public function __toString() {
32		return "Class A object";
33	}
34}
35
36// heredoc string
37$heredoc = <<<EOT
38hello world
39EOT;
40
41// get a resource variable
42$fp = fopen(__FILE__, "r");
43
44// unexpected values to be passed to $string argument
45$inputs = array(
46
47// int data
48/*1*/  0,
49       1,
50       12345,
51       -2345,
52
53// float data
54/*5*/  10.5,
55       -10.5,
56       12.3456789000e10,
57       12.3456789000E-10,
58       .5,
59
60// null data
61/*10*/ NULL,
62       null,
63
64// boolean data
65/*12*/ true,
66       false,
67       TRUE,
68       FALSE,
69
70// empty data
71/*16*/ "",
72       '',
73
74// string data
75/*18*/ "string",
76       'string',
77       $heredoc,
78
79// object data
80/*21*/ new classA(),
81
82// undefined data
83/*22*/ @$undefined_var,
84
85// unset data
86/*23*/ @$unset_var,
87
88// resource variable
89/*24*/ $fp
90);
91
92// loop through each element of $inputs to check the behavior of mb_ereg()
93$iterator = 1;
94foreach($inputs as $input) {
95	if (@is_array($regs)){
96		$regs = null;
97	}
98	echo "\n-- Iteration $iterator --\n";
99	var_dump( mb_ereg($pattern, $input, $regs) );
100	var_dump($regs);
101	$iterator++;
102};
103
104fclose($fp);
105
106echo "Done";
107
108?>
109
110--EXPECTF--
111*** Testing mb_ereg() : usage variations ***
112
113-- Iteration 1 --
114bool(false)
115NULL
116
117-- Iteration 2 --
118bool(false)
119NULL
120
121-- Iteration 3 --
122bool(false)
123NULL
124
125-- Iteration 4 --
126bool(false)
127NULL
128
129-- Iteration 5 --
130bool(false)
131NULL
132
133-- Iteration 6 --
134bool(false)
135NULL
136
137-- Iteration 7 --
138bool(false)
139NULL
140
141-- Iteration 8 --
142bool(false)
143NULL
144
145-- Iteration 9 --
146bool(false)
147NULL
148
149-- Iteration 10 --
150bool(false)
151NULL
152
153-- Iteration 11 --
154bool(false)
155NULL
156
157-- Iteration 12 --
158bool(false)
159NULL
160
161-- Iteration 13 --
162bool(false)
163NULL
164
165-- Iteration 14 --
166bool(false)
167NULL
168
169-- Iteration 15 --
170bool(false)
171NULL
172
173-- Iteration 16 --
174bool(false)
175NULL
176
177-- Iteration 17 --
178bool(false)
179NULL
180
181-- Iteration 18 --
182int(3)
183array(1) {
184  [0]=>
185  string(3) "str"
186}
187
188-- Iteration 19 --
189int(3)
190array(1) {
191  [0]=>
192  string(3) "str"
193}
194
195-- Iteration 20 --
196bool(false)
197NULL
198
199-- Iteration 21 --
200bool(false)
201NULL
202
203-- Iteration 22 --
204bool(false)
205NULL
206
207-- Iteration 23 --
208bool(false)
209NULL
210
211-- Iteration 24 --
212
213Warning: mb_ereg() expects parameter 2 to be string, resource given in %s on line %d
214bool(false)
215NULL
216Done
217