1--TEST--
2Test mkdir() function : usage variation: different types for mode
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 = 'mkdirVar2.tmp';
26
27//get an unset variable
28$unset_var = 10;
29unset ($unset_var);
30
31// define some classes
32class classWithToString
33{
34	public function __toString() {
35		return "Class A object";
36	}
37}
38
39class classWithoutToString
40{
41}
42
43// heredoc string
44$heredoc = <<<EOT
45hello world
46EOT;
47
48// add arrays
49$index_array = array (1, 2, 3);
50$assoc_array = array ('one' => 1, 'two' => 2);
51
52//array of values to iterate over
53$inputs = array(
54
55      // float data
56      'float 10.5' => 10.5,
57      'float -10.5' => -10.5,
58      'float 12.3456789000e10' => 12.3456789000e10,
59      'float -12.3456789000e10' => -12.3456789000e10,
60      'float .5' => .5,
61
62      // array data
63      'empty array' => array(),
64      'int indexed array' => $index_array,
65      'associative array' => $assoc_array,
66      'nested arrays' => array('foo', $index_array, $assoc_array),
67
68      // null data
69      'uppercase NULL' => NULL,
70      'lowercase null' => null,
71
72      // boolean data
73      'lowercase true' => true,
74      'lowercase false' =>false,
75      'uppercase TRUE' =>TRUE,
76      'uppercase FALSE' =>FALSE,
77
78      // empty data
79      'empty string DQ' => "",
80      'empty string SQ' => '',
81
82      // string data
83      'string DQ' => "string",
84      'string SQ' => 'string',
85      'mixed case string' => "sTrInG",
86      'heredoc' => $heredoc,
87
88      // object data
89      'instance of classWithToString' => new classWithToString(),
90      'instance of classWithoutToString' => new classWithoutToString(),
91
92      // undefined data
93      'undefined var' => @$undefined_var,
94
95      // unset data
96      'unset var' => @$unset_var,
97);
98
99// loop through each element of the array for mode
100
101foreach($inputs as $key =>$value) {
102      echo "\n--$key--\n";
103      $h = mkdir($pathname, $value);
104      if ($h === true) {
105         echo "Directory created\n";
106         rmdir($pathname);
107      }
108};
109
110?>
111===DONE===
112--EXPECTF--
113*** Testing mkdir() : usage variation ***
114
115--float 10.5--
116Directory created
117
118--float -10.5--
119Directory created
120
121--float 12.3456789000e10--
122Directory created
123
124--float -12.3456789000e10--
125Directory created
126
127--float .5--
128Directory created
129
130--empty array--
131Error: 2 - mkdir() expects parameter 2 to be long, array given, %s(%d)
132
133--int indexed array--
134Error: 2 - mkdir() expects parameter 2 to be long, array given, %s(%d)
135
136--associative array--
137Error: 2 - mkdir() expects parameter 2 to be long, array given, %s(%d)
138
139--nested arrays--
140Error: 2 - mkdir() expects parameter 2 to be long, array given, %s(%d)
141
142--uppercase NULL--
143Directory created
144
145--lowercase null--
146Directory created
147
148--lowercase true--
149Directory created
150
151--lowercase false--
152Directory created
153
154--uppercase TRUE--
155Directory created
156
157--uppercase FALSE--
158Directory created
159
160--empty string DQ--
161Error: 2 - mkdir() expects parameter 2 to be long, string given, %s(%d)
162
163--empty string SQ--
164Error: 2 - mkdir() expects parameter 2 to be long, string given, %s(%d)
165
166--string DQ--
167Error: 2 - mkdir() expects parameter 2 to be long, string given, %s(%d)
168
169--string SQ--
170Error: 2 - mkdir() expects parameter 2 to be long, string given, %s(%d)
171
172--mixed case string--
173Error: 2 - mkdir() expects parameter 2 to be long, string given, %s(%d)
174
175--heredoc--
176Error: 2 - mkdir() expects parameter 2 to be long, string given, %s(%d)
177
178--instance of classWithToString--
179Error: 2 - mkdir() expects parameter 2 to be long, object given, %s(%d)
180
181--instance of classWithoutToString--
182Error: 2 - mkdir() expects parameter 2 to be long, object given, %s(%d)
183
184--undefined var--
185Directory created
186
187--unset var--
188Directory created
189===DONE===
190