1--TEST-- 2Test opendir() function : usage variations - different data types as $path arg 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) != 'WIN') { 6 die("skip Valid only on Windows"); 7} 8?> 9--FILE-- 10<?php 11/* Prototype : mixed opendir(string $path[, resource $context]) 12 * Description: Open a directory and return a dir_handle 13 * Source code: ext/standard/dir.c 14 */ 15 16/* 17 * Pass different data types as $path argument to opendir() to test behaviour 18 * Where possible, an existing directory has been entered as a string value 19 */ 20 21echo "*** Testing opendir() : usage variations ***\n"; 22 23// create directory to be passed as string value where possible 24$path = dirname(__FILE__) . "/opendir_variation1"; 25mkdir($path); 26 27//get an unset variable 28$unset_var = 10; 29unset ($unset_var); 30 31// get a class 32class classA { 33 34 var $path; 35 function __construct($path) { 36 $this->path = $path; 37 } 38 public function __toString() { 39 return $this->path; 40 } 41} 42 43// heredoc string 44$heredoc = <<<EOT 45$path 46EOT; 47 48// get a resource variable 49$fp = fopen(__FILE__, "r"); 50 51// unexpected values to be passed to $path argument 52$inputs = array( 53 54 // int data 55/*1*/ 0, 56 1, 57 12345, 58 -2345, 59 60 // float data 61/*5*/ 10.5, 62 -10.5, 63 12.3456789000e10, 64 12.3456789000E-10, 65 .5, 66 67 // null data 68/*10*/ NULL, 69 null, 70 71 // boolean data 72/*12*/ true, 73 false, 74 TRUE, 75 FALSE, 76 77 // empty data 78/*16*/ "", 79 '', 80 array(), 81 82 // string data 83/*19*/ "$path", 84 'string', 85 $heredoc, 86 87 // object data 88/*22*/ new classA($path), 89 90 // undefined data 91/*23*/ @$undefined_var, 92 93 // unset data 94/*24*/ @$unset_var, 95 96 // resource variable 97/*25*/ $fp 98); 99 100// loop through each element of $inputs to check the behavior of opendir() 101$iterator = 1; 102foreach($inputs as $input) { 103 echo "\n-- Iteration $iterator --\n"; 104 var_dump( $dh = opendir($input) ); 105 if ($dh) { 106 closedir($dh); 107 } 108 $iterator++; 109}; 110 111fclose($fp); 112?> 113===DONE=== 114--CLEAN-- 115<?php 116$path = dirname(__FILE__) . "/opendir_variation1"; 117rmdir($path); 118?> 119--EXPECTF-- 120*** Testing opendir() : usage variations *** 121 122-- Iteration 1 -- 123 124Warning: opendir(0,0): The system cannot find the file specified. (code: 2) in %s on line %d 125 126Warning: opendir(0): failed to open dir: %s in %s on line %d 127bool(false) 128 129-- Iteration 2 -- 130 131Warning: opendir(1,1): The system cannot find the file specified. (code: 2) in %s on line %d 132 133Warning: opendir(1): failed to open dir: %s in %s on line %d 134bool(false) 135 136-- Iteration 3 -- 137 138Warning: opendir(12345,12345): The system cannot find the file specified. (code: 2) in %s on line %d 139 140Warning: opendir(12345): failed to open dir: %s in %s on line %d 141bool(false) 142 143-- Iteration 4 -- 144 145Warning: opendir(-2345,-2345): The system cannot find the file specified. (code: 2) in %s on line %d 146 147Warning: opendir(-2345): failed to open dir: %s in %s on line %d 148bool(false) 149 150-- Iteration 5 -- 151 152Warning: opendir(10.5,10.5): The system cannot find the file specified. (code: 2) in %s on line %d 153 154Warning: opendir(10.5): failed to open dir: %s in %s on line %d 155bool(false) 156 157-- Iteration 6 -- 158 159Warning: opendir(-10.5,-10.5): The system cannot find the file specified. (code: 2) in %s on line %d 160 161Warning: opendir(-10.5): failed to open dir: %s in %s on line %d 162bool(false) 163 164-- Iteration 7 -- 165 166Warning: opendir(123456789000,123456789000): The system cannot find the file specified. (code: 2) in %s on line %d 167 168Warning: opendir(123456789000): failed to open dir: %s in %s on line %d 169bool(false) 170 171-- Iteration 8 -- 172 173Warning: opendir(1.23456789E-9,1.23456789E-9): The system cannot find the file specified. (code: 2) in %s on line %d 174 175Warning: opendir(1.23456789E-9): failed to open dir: %s in %s on line %d 176bool(false) 177 178-- Iteration 9 -- 179 180Warning: opendir(0.5,0.5): The system cannot find the file specified. (code: 2) in %s on line %d 181 182Warning: opendir(0.5): failed to open dir: %s in %s on line %d 183bool(false) 184 185-- Iteration 10 -- 186bool(false) 187 188-- Iteration 11 -- 189bool(false) 190 191-- Iteration 12 -- 192 193Warning: opendir(1,1): The system cannot find the file specified. (code: 2) in %s on line %d 194 195Warning: opendir(1): failed to open dir: %s in %s on line %d 196bool(false) 197 198-- Iteration 13 -- 199bool(false) 200 201-- Iteration 14 -- 202 203Warning: opendir(1,1): The system cannot find the file specified. (code: 2) in %s on line %d 204 205Warning: opendir(1): failed to open dir: %s in %s on line %d 206bool(false) 207 208-- Iteration 15 -- 209bool(false) 210 211-- Iteration 16 -- 212bool(false) 213 214-- Iteration 17 -- 215bool(false) 216 217-- Iteration 18 -- 218 219Warning: opendir() expects parameter 1 to be a valid path, array given in %s on line %d 220NULL 221 222-- Iteration 19 -- 223resource(%d) of type (stream) 224 225-- Iteration 20 -- 226 227Warning: opendir(string,string): The system cannot find the file specified. (code: 2) in %s on line %d 228 229Warning: opendir(string): failed to open dir: %s in %s on line %d 230bool(false) 231 232-- Iteration 21 -- 233resource(%d) of type (stream) 234 235-- Iteration 22 -- 236resource(%d) of type (stream) 237 238-- Iteration 23 -- 239bool(false) 240 241-- Iteration 24 -- 242bool(false) 243 244-- Iteration 25 -- 245 246Warning: opendir() expects parameter 1 to be a valid path, resource given in %s on line %d 247NULL 248===DONE=== 249