1--TEST--
2Test mb_ereg() function : usage variations - pass different data types to $pattern argument
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 * Pass different data types to $pattern argument
17 */
18
19echo "*** Testing mb_ereg() : usage variations ***\n";
20
21// Initialise function arguments not being substituted (if any)
22$string = 'string value';
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 $pattern 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// boolean data
61/*10*/ true,
62       TRUE,
63
64// string data
65/*12*/ "string",
66       'string',
67       $heredoc,
68
69// object data
70/*15*/ new classA(),
71
72// resource variable
73/*16*/ $fp
74);
75
76// loop through each element of $inputs to check the behavior of mb_ereg()
77$iterator = 1;
78foreach($inputs as $input) {
79	if (@is_array($regs)){
80		$regs = null;
81	}
82	echo "\n-- Iteration $iterator --\n";
83	var_dump( mb_ereg($input, $string, $regs) );
84	var_dump($regs);
85	$iterator++;
86};
87
88fclose($fp);
89
90echo "Done";
91?>
92
93--EXPECTF--
94*** Testing mb_ereg() : usage variations ***
95
96-- Iteration 1 --
97bool(false)
98NULL
99
100-- Iteration 2 --
101bool(false)
102NULL
103
104-- Iteration 3 --
105bool(false)
106NULL
107
108-- Iteration 4 --
109bool(false)
110NULL
111
112-- Iteration 5 --
113bool(false)
114NULL
115
116-- Iteration 6 --
117bool(false)
118NULL
119
120-- Iteration 7 --
121bool(false)
122NULL
123
124-- Iteration 8 --
125bool(false)
126NULL
127
128-- Iteration 9 --
129bool(false)
130NULL
131
132-- Iteration 10 --
133bool(false)
134NULL
135
136-- Iteration 11 --
137bool(false)
138NULL
139
140-- Iteration 12 --
141int(6)
142array(1) {
143  [0]=>
144  string(6) "string"
145}
146
147-- Iteration 13 --
148int(6)
149array(1) {
150  [0]=>
151  string(6) "string"
152}
153
154-- Iteration 14 --
155bool(false)
156NULL
157
158-- Iteration 15 --
159bool(false)
160NULL
161
162-- Iteration 16 --
163bool(false)
164NULL
165Done
166