1--TEST--
2Test mkdir() function : usage variation: different types for recursive
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--FILE--
6<?php
7/* Prototype  : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]])
8 * Description: Create a directory
9 * Source code: ext/standard/file.c
10 * Alias to functions:
11 */
12
13echo "*** Testing mkdir() : usage variation ***\n";
14
15// Define error handler
16function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
17	if (error_reporting() != 0) {
18		// report non-silenced errors
19		echo "Error: $err_no - $err_msg, $filename($linenum)\n";
20	}
21}
22set_error_handler('test_error_handler');
23
24// Initialise function arguments not being substituted (if any)
25$pathname = 'mkdirVar3.tmp';
26$mode = 0777;
27
28//get an unset variable
29$unset_var = 10;
30unset ($unset_var);
31
32// define some classes
33class classWithToString
34{
35	public function __toString() {
36		return "Class A object";
37	}
38}
39
40class classWithoutToString
41{
42}
43
44// heredoc string
45$heredoc = <<<EOT
46hello world
47EOT;
48
49// add arrays
50$index_array = array (1, 2, 3);
51$assoc_array = array ('one' => 1, 'two' => 2);
52
53//array of values to iterate over
54$inputs = array(
55
56      // int data
57      'int 0' => 0,
58      'int 1' => 1,
59      'int 12345' => 12345,
60      'int -12345' => -2345,
61
62      // float data
63      'float 10.5' => 10.5,
64      'float -10.5' => -10.5,
65      'float 12.3456789000e10' => 12.3456789000e10,
66      'float -12.3456789000e10' => -12.3456789000e10,
67      'float .5' => .5,
68
69      // array data
70      'empty array' => array(),
71      'int indexed array' => $index_array,
72      'associative array' => $assoc_array,
73      'nested arrays' => array('foo', $index_array, $assoc_array),
74
75      // null data
76      'uppercase NULL' => NULL,
77      'lowercase null' => null,
78
79      // boolean data
80      'lowercase true' => true,
81      'lowercase false' =>false,
82      'uppercase TRUE' =>TRUE,
83      'uppercase FALSE' =>FALSE,
84
85      // empty data
86      'empty string DQ' => "",
87      'empty string SQ' => '',
88
89      // string data
90      'string DQ' => "string",
91      'string SQ' => 'string',
92      'mixed case string' => "sTrInG",
93      'heredoc' => $heredoc,
94
95      // object data
96      'instance of classWithToString' => new classWithToString(),
97      'instance of classWithoutToString' => new classWithoutToString(),
98
99      // undefined data
100      'undefined var' => @$undefined_var,
101
102      // unset data
103      'unset var' => @$unset_var,
104);
105
106// loop through each element of the array for recursive
107
108foreach($inputs as $key =>$value) {
109      echo "\n--$key--\n";
110      $h = mkdir($pathname, $mode, $value);
111      if ($h === true) {
112         echo "Directory created\n";
113         rmdir($pathname);
114      }
115};
116
117?>
118===DONE===
119--EXPECTF--
120*** Testing mkdir() : usage variation ***
121
122--int 0--
123Directory created
124
125--int 1--
126Directory created
127
128--int 12345--
129Directory created
130
131--int -12345--
132Directory created
133
134--float 10.5--
135Directory created
136
137--float -10.5--
138Directory created
139
140--float 12.3456789000e10--
141Directory created
142
143--float -12.3456789000e10--
144Directory created
145
146--float .5--
147Directory created
148
149--empty array--
150Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d)
151
152--int indexed array--
153Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d)
154
155--associative array--
156Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d)
157
158--nested arrays--
159Error: 2 - mkdir() expects parameter 3 to be boolean, array given, %s(%d)
160
161--uppercase NULL--
162Directory created
163
164--lowercase null--
165Directory created
166
167--lowercase true--
168Directory created
169
170--lowercase false--
171Directory created
172
173--uppercase TRUE--
174Directory created
175
176--uppercase FALSE--
177Directory created
178
179--empty string DQ--
180Directory created
181
182--empty string SQ--
183Directory created
184
185--string DQ--
186Directory created
187
188--string SQ--
189Directory created
190
191--mixed case string--
192Directory created
193
194--heredoc--
195Directory created
196
197--instance of classWithToString--
198Error: 2 - mkdir() expects parameter 3 to be boolean, object given, %s(%d)
199
200--instance of classWithoutToString--
201Error: 2 - mkdir() expects parameter 3 to be boolean, object given, %s(%d)
202
203--undefined var--
204Directory created
205
206--unset var--
207Directory created
208===DONE===
209