1--TEST--
2Test dir() function : usage variations - unexpected value for 'dir' argument
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip.. Not valid for Windows');
7}
8?>
9--FILE--
10<?php
11/*
12 * Prototype  : object dir(string $directory[, resource $context])
13 * Description: Directory class with properties, handle and class and methods read, rewind and close
14 * Source code: ext/standard/dir.c
15 */
16
17/*
18 * Passing non string values to 'directory' argument of dir() and see
19 * that the function outputs proper warning messages wherever expected.
20 */
21
22echo "*** Testing dir() : unexpected values for \$directory argument ***\n";
23
24// get an unset variable
25$unset_var = 10;
26unset($unset_var);
27
28class A
29{
30  public $var;
31  public function init() {
32    $this->var = 10;
33  }
34}
35
36// get a resource variable
37$fp = fopen(__FILE__, "r"); // get a file handle
38$dfp = opendir( dirname(__FILE__) ); // get a dir handle
39
40// unexpected values to be passed to $directory argument
41$unexpected_values = array (
42
43       // array data
44/*1*/  array(),
45       array(0),
46       array(1),
47       array(1, 2),
48       array('color' => 'red', 'item' => 'pen'),
49
50       // null data
51/*6*/  NULL,
52       null,
53
54       // boolean data
55/*8*/  true,
56       false,
57       TRUE,
58       FALSE,
59
60       // empty data
61/*12*/ "",
62       '',
63
64       // undefined data
65/*14*/ @$undefined_var,
66
67       // unset data
68/*15*/ @$unset_var,
69
70       // resource variable(dir and file handle)
71/*16*/ $fp,
72       $dfp,
73
74       // object data
75/*18*/ new A()
76);
77
78// loop through various elements of $unexpected_values to check the behavior of dir()
79$iterator = 1;
80foreach( $unexpected_values as $unexpected_value ) {
81  echo "\n-- Iteration $iterator --\n";
82  var_dump( dir($unexpected_value) );
83  $iterator++;
84}
85
86fclose($fp);
87closedir($dfp);
88echo "Done";
89?>
90--EXPECTF--
91*** Testing dir() : unexpected values for $directory argument ***
92
93-- Iteration 1 --
94
95Warning: dir() expects parameter 1 to be a valid path, array given in %s on line %d
96NULL
97
98-- Iteration 2 --
99
100Warning: dir() expects parameter 1 to be a valid path, array given in %s on line %d
101NULL
102
103-- Iteration 3 --
104
105Warning: dir() expects parameter 1 to be a valid path, array given in %s on line %d
106NULL
107
108-- Iteration 4 --
109
110Warning: dir() expects parameter 1 to be a valid path, array given in %s on line %d
111NULL
112
113-- Iteration 5 --
114
115Warning: dir() expects parameter 1 to be a valid path, array given in %s on line %d
116NULL
117
118-- Iteration 6 --
119bool(false)
120
121-- Iteration 7 --
122bool(false)
123
124-- Iteration 8 --
125
126Warning: dir(1): failed to open dir: %s in %s on line %d
127bool(false)
128
129-- Iteration 9 --
130bool(false)
131
132-- Iteration 10 --
133
134Warning: dir(1): failed to open dir: %s in %s on line %d
135bool(false)
136
137-- Iteration 11 --
138bool(false)
139
140-- Iteration 12 --
141bool(false)
142
143-- Iteration 13 --
144bool(false)
145
146-- Iteration 14 --
147bool(false)
148
149-- Iteration 15 --
150bool(false)
151
152-- Iteration 16 --
153
154Warning: dir() expects parameter 1 to be a valid path, resource given in %s on line %d
155NULL
156
157-- Iteration 17 --
158
159Warning: dir() expects parameter 1 to be a valid path, resource given in %s on line %d
160NULL
161
162-- Iteration 18 --
163
164Warning: dir() expects parameter 1 to be a valid path, object given in %s on line %d
165NULL
166Done
167