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