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