1--TEST--
2Test mb_strtolower() function : usage variations - pass different data types as $sourcestring 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 $sourcestring argument to test behaviour of mb_strtolower()
17 */
18
19echo "*** Testing mb_strtolower() : usage variations ***\n";
20
21
22//get an unset variable
23$unset_var = 10;
24unset ($unset_var);
25
26// get a class
27class classA
28{
29  public function __toString() {
30    return "Class A object";
31  }
32}
33
34// heredoc string
35$heredoc = <<<EOT
36Hello World
37EOT;
38
39// get a resource variable
40$fp = fopen(__FILE__, "r");
41
42// unexpected values to be passed to $sourcestring argument
43$inputs = array(
44
45       // int data
46/*1*/  0,
47       1,
48       12345,
49       -2345,
50
51       // float data
52/*5*/  10.5,
53       -10.5,
54       12.3456789000e10,
55       12.3456789000E-10,
56       .5,
57
58       // null data
59/*10*/ NULL,
60       null,
61
62       // boolean data
63/*12*/ true,
64       false,
65       TRUE,
66       FALSE,
67
68       // empty data
69/*16*/ "",
70       '',
71
72       // string data
73/*18*/ "String",
74       'String',
75       $heredoc,
76
77       // object data
78/*21*/ new classA(),
79
80       // undefined data
81/*22*/ @$undefined_var,
82
83       // unset data
84/*23*/ @$unset_var,
85
86       // resource variable
87/*24*/ $fp
88);
89
90// loop through each element of $inputs to check the behavior of mb_strtolower()
91$iterator = 1;
92foreach($inputs as $input) {
93  echo "\n-- Iteration $iterator --\n";
94  var_dump( mb_strtolower($input) );
95  $iterator++;
96};
97
98fclose($fp);
99
100echo "Done";
101?>
102--EXPECTF--
103*** Testing mb_strtolower() : usage variations ***
104
105-- Iteration 1 --
106string(1) "0"
107
108-- Iteration 2 --
109string(1) "1"
110
111-- Iteration 3 --
112string(5) "12345"
113
114-- Iteration 4 --
115string(5) "-2345"
116
117-- Iteration 5 --
118string(4) "10.5"
119
120-- Iteration 6 --
121string(5) "-10.5"
122
123-- Iteration 7 --
124string(12) "123456789000"
125
126-- Iteration 8 --
127string(13) "1.23456789e-9"
128
129-- Iteration 9 --
130string(3) "0.5"
131
132-- Iteration 10 --
133string(0) ""
134
135-- Iteration 11 --
136string(0) ""
137
138-- Iteration 12 --
139string(1) "1"
140
141-- Iteration 13 --
142string(0) ""
143
144-- Iteration 14 --
145string(1) "1"
146
147-- Iteration 15 --
148string(0) ""
149
150-- Iteration 16 --
151string(0) ""
152
153-- Iteration 17 --
154string(0) ""
155
156-- Iteration 18 --
157string(6) "string"
158
159-- Iteration 19 --
160string(6) "string"
161
162-- Iteration 20 --
163string(11) "hello world"
164
165-- Iteration 21 --
166string(14) "class a object"
167
168-- Iteration 22 --
169string(0) ""
170
171-- Iteration 23 --
172string(0) ""
173
174-- Iteration 24 --
175
176Warning: mb_strtolower() expects parameter 1 to be string, resource given in %s on line %d
177NULL
178Done