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 Valid only on 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 string, array given in %s on line %d 96NULL 97 98-- Iteration 2 -- 99 100Warning: dir() expects parameter 1 to be string, array given in %s on line %d 101NULL 102 103-- Iteration 3 -- 104 105Warning: dir() expects parameter 1 to be string, array given in %s on line %d 106NULL 107 108-- Iteration 4 -- 109 110Warning: dir() expects parameter 1 to be string, array given in %s on line %d 111NULL 112 113-- Iteration 5 -- 114 115Warning: dir() expects parameter 1 to be string, 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,1): The system cannot find the file specified. (code: 2) in %s on line %d 127 128Warning: dir(1): failed to open dir: %s in %s on line %d 129bool(false) 130 131-- Iteration 9 -- 132bool(false) 133 134-- Iteration 10 -- 135 136Warning: dir(1,1): The system cannot find the file specified. (code: 2) in %s on line %d 137 138Warning: dir(1): failed to open dir: %s in %s on line %d 139bool(false) 140 141-- Iteration 11 -- 142bool(false) 143 144-- Iteration 12 -- 145bool(false) 146 147-- Iteration 13 -- 148bool(false) 149 150-- Iteration 14 -- 151bool(false) 152 153-- Iteration 15 -- 154bool(false) 155 156-- Iteration 16 -- 157 158Warning: dir() expects parameter 1 to be string, resource given in %s on line %d 159NULL 160 161-- Iteration 17 -- 162 163Warning: dir() expects parameter 1 to be string, resource given in %s on line %d 164NULL 165 166-- Iteration 18 -- 167 168Warning: dir() expects parameter 1 to be string, object given in %s on line %d 169NULL 170Done