1--TEST-- 2Test readdir() function : usage variations - different file names 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 * Pass a directory handle pointing to a directory that contains 13 * files with different file names to test how readdir() reads them 14 */ 15 16echo "*** Testing readdir() : usage variations ***\n"; 17 18$dir_path = __DIR__ . "/私はガラスを食べられますreaddir_variation4/"; 19mkdir($dir_path); 20 21// heredoc string 22$heredoc = <<<EOT 23hd_file 24EOT; 25 26$inputs = array( 27 28 // int data 29/*1*/ 0, 30 1, 31 12345, 32 -2345, 33 34 // float data 35/*5*/ 10.5, 36 -10.5, 37 12.3456789000e10, 38 12.3456789000E-10, 39 .5, 40 41 // empty data 42/*10*/ "", 43 array(), 44 45 // string data 46/*12*/ "double_file", 47 'single_file', 48 $heredoc, 49); 50 51$iterator = 1; 52foreach($inputs as $key => $input) { 53 echo "\n-- Iteration $iterator --\n"; 54 $handle = "fp{$iterator}"; 55 var_dump( $$handle = @fopen($dir_path . "私はガラスを食べられます$input.tmp", 'w') ); 56 var_dump( fwrite($$handle, $key)); 57 fclose($$handle); 58 $iterator++; 59}; 60 61echo "\n-- Call to readdir() --\n"; 62$dir_handle = opendir($dir_path); 63while(FALSE !== ($file = readdir($dir_handle))){ 64 65 // different OS order files differently so will 66 // store file names into an array so can use sorted in expected output 67 $contents[] = $file; 68 69 // remove files while going through directory 70 @unlink($dir_path . $file); 71} 72 73// more important to check that all contents are present than order they are returned in 74sort($contents); 75var_dump($contents); 76 77closedir($dir_handle); 78?> 79--CLEAN-- 80<?php 81$dir_path = __DIR__ . "/私はガラスを食べられますreaddir_variation4/"; 82rmdir($dir_path); 83?> 84--EXPECTF-- 85*** Testing readdir() : usage variations *** 86 87-- Iteration 1 -- 88resource(%d) of type (stream) 89int(1) 90 91-- Iteration 2 -- 92resource(%d) of type (stream) 93int(1) 94 95-- Iteration 3 -- 96resource(%d) of type (stream) 97int(1) 98 99-- Iteration 4 -- 100resource(%d) of type (stream) 101int(1) 102 103-- Iteration 5 -- 104resource(%d) of type (stream) 105int(1) 106 107-- Iteration 6 -- 108resource(%d) of type (stream) 109int(1) 110 111-- Iteration 7 -- 112resource(%d) of type (stream) 113int(1) 114 115-- Iteration 8 -- 116resource(%d) of type (stream) 117int(1) 118 119-- Iteration 9 -- 120resource(%d) of type (stream) 121int(1) 122 123-- Iteration 10 -- 124resource(%d) of type (stream) 125int(1) 126 127-- Iteration 11 -- 128resource(%d) of type (stream) 129int(2) 130 131-- Iteration 12 -- 132resource(%d) of type (stream) 133int(2) 134 135-- Iteration 13 -- 136resource(%d) of type (stream) 137int(2) 138 139-- Iteration 14 -- 140resource(%d) of type (stream) 141int(2) 142 143-- Call to readdir() -- 144array(16) { 145 [0]=> 146 string(1) "." 147 [1]=> 148 string(2) ".." 149 [2]=> 150 string(45) "私はガラスを食べられます-10.5.tmp" 151 [3]=> 152 string(45) "私はガラスを食べられます-2345.tmp" 153 [4]=> 154 string(40) "私はガラスを食べられます.tmp" 155 [5]=> 156 string(43) "私はガラスを食べられます0.5.tmp" 157 [6]=> 158 string(41) "私はガラスを食べられます0.tmp" 159 [7]=> 160 string(53) "私はガラスを食べられます1.23456789E-9.tmp" 161 [8]=> 162 string(41) "私はガラスを食べられます1.tmp" 163 [9]=> 164 string(44) "私はガラスを食べられます10.5.tmp" 165 [10]=> 166 string(45) "私はガラスを食べられます12345.tmp" 167 [11]=> 168 string(52) "私はガラスを食べられます123456789000.tmp" 169 [12]=> 170 string(45) "私はガラスを食べられますArray.tmp" 171 [13]=> 172 string(51) "私はガラスを食べられますdouble_file.tmp" 173 [14]=> 174 string(47) "私はガラスを食べられますhd_file.tmp" 175 [15]=> 176 string(51) "私はガラスを食べられますsingle_file.tmp" 177} 178