1--TEST--
2Test mb_strtoupper() function : usage varitations - Pass different data types as $encoding arg
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_strtoupper') or die("skip mb_strtoupper() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : string mb_strtoupper(string $sourcestring [, string $encoding]
11 * Description: Returns a uppercased version of $sourcestring
12 * Source code: ext/mbstring/mbstring.c
13 */
14
15/*
16 * Pass different data types as $encoding argument to mb_strtoupper() to test behaviour
17 * Where possible, 'UTF-8' is entered as string value
18 */
19
20echo "*** Testing mb_strtoupper() : usage variations ***\n";
21
22// Initialise function arguments not being substituted
23$sourcestring = '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_strtoupper()
94$iterator = 1;
95foreach($inputs as $input) {
96  echo "\n-- Iteration $iterator --\n";
97  $res = mb_strtoupper($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_strtoupper() : usage variations ***
113
114-- Iteration 1 --
115
116Warning: mb_strtoupper(): Unknown encoding "0" in %s on line %d
117bool(false)
118
119-- Iteration 2 --
120
121Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d
122bool(false)
123
124-- Iteration 3 --
125
126Warning: mb_strtoupper(): Unknown encoding "12345" in %s on line %d
127bool(false)
128
129-- Iteration 4 --
130
131Warning: mb_strtoupper(): Unknown encoding "-2345" in %s on line %d
132bool(false)
133
134-- Iteration 5 --
135
136Warning: mb_strtoupper(): Unknown encoding "10.5" in %s on line %d
137bool(false)
138
139-- Iteration 6 --
140
141Warning: mb_strtoupper(): Unknown encoding "-10.5" in %s on line %d
142bool(false)
143
144-- Iteration 7 --
145
146Warning: mb_strtoupper(): Unknown encoding "123456789000" in %s on line %d
147bool(false)
148
149-- Iteration 8 --
150
151Warning: mb_strtoupper(): Unknown encoding "1.23456789E-9" in %s on line %d
152bool(false)
153
154-- Iteration 9 --
155
156Warning: mb_strtoupper(): Unknown encoding "0.5" in %s on line %d
157bool(false)
158
159-- Iteration 10 --
160string(24) "48454c4c4f2c20574f524c44"
161
162-- Iteration 11 --
163string(24) "48454c4c4f2c20574f524c44"
164
165-- Iteration 12 --
166
167Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d
168bool(false)
169
170-- Iteration 13 --
171
172Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d
173bool(false)
174
175-- Iteration 14 --
176
177Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d
178bool(false)
179
180-- Iteration 15 --
181
182Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d
183bool(false)
184
185-- Iteration 16 --
186
187Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d
188bool(false)
189
190-- Iteration 17 --
191
192Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d
193bool(false)
194
195-- Iteration 18 --
196string(24) "48454c4c4f2c20574f524c44"
197
198-- Iteration 19 --
199string(24) "48454c4c4f2c20574f524c44"
200
201-- Iteration 20 --
202string(24) "48454c4c4f2c20574f524c44"
203
204-- Iteration 21 --
205string(24) "48454c4c4f2c20574f524c44"
206
207-- Iteration 22 --
208string(24) "48454c4c4f2c20574f524c44"
209
210-- Iteration 23 --
211string(24) "48454c4c4f2c20574f524c44"
212
213-- Iteration 24 --
214
215Warning: mb_strtoupper() expects parameter 2 to be string, resource given in %s on line %d
216NULL
217Done
218