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