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--EXPECT--
93*** Testing mb_ereg() : usage variations ***
94
95-- Iteration 1 --
96bool(false)
97array(0) {
98}
99
100-- Iteration 2 --
101bool(false)
102array(0) {
103}
104
105-- Iteration 3 --
106bool(false)
107array(0) {
108}
109
110-- Iteration 4 --
111bool(false)
112array(0) {
113}
114
115-- Iteration 5 --
116bool(false)
117array(0) {
118}
119
120-- Iteration 6 --
121bool(false)
122array(0) {
123}
124
125-- Iteration 7 --
126bool(false)
127array(0) {
128}
129
130-- Iteration 8 --
131bool(false)
132array(0) {
133}
134
135-- Iteration 9 --
136bool(false)
137array(0) {
138}
139
140-- Iteration 10 --
141bool(false)
142array(0) {
143}
144
145-- Iteration 11 --
146bool(false)
147array(0) {
148}
149
150-- Iteration 12 --
151int(6)
152array(1) {
153  [0]=>
154  string(6) "string"
155}
156
157-- Iteration 13 --
158int(6)
159array(1) {
160  [0]=>
161  string(6) "string"
162}
163
164-- Iteration 14 --
165bool(false)
166array(0) {
167}
168
169-- Iteration 15 --
170bool(false)
171array(0) {
172}
173
174-- Iteration 16 --
175bool(false)
176array(0) {
177}
178Done
179