1--TEST-- 2Test scandir() function : usage variations - different sorting constants 3--FILE-- 4<?php 5/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) 6 * Description: List files & directories inside the specified path 7 * Source code: ext/standard/dir.c 8 */ 9 10printf("SCANDIR_SORT_ASCENDING: %d\n", SCANDIR_SORT_ASCENDING); 11printf("SCANDIR_SORT_DESCENDING: %d\n", SCANDIR_SORT_DESCENDING); 12printf("SCANDIR_SORT_NONE: %d\n", SCANDIR_SORT_NONE); 13 14/* 15 * Pass different integers as $sorting_order argument to test how scandir() 16 * re-orders the array 17 */ 18 19echo "*** Testing scandir() : usage variations ***\n"; 20 21// include for create_files/delete_files functions 22include(dirname(__FILE__) . '/../file/file.inc'); 23 24// create directory and files 25$dir = dirname(__FILE__) . '/scandir_variation10'; 26mkdir($dir); 27@create_files($dir, 2); 28 29// Deterministic tests. 30var_dump(scandir($dir, SCANDIR_SORT_ASCENDING)); 31var_dump(scandir($dir, SCANDIR_SORT_DESCENDING)); 32 33// Non-deterministic tests. 34$files = scandir($dir, SCANDIR_SORT_NONE); 35var_dump(count($files)); 36var_dump(in_array('.', $files)); 37var_dump(in_array('..', $files)); 38var_dump(in_array('file1.tmp', $files)); 39var_dump(in_array('file2.tmp', $files)); 40 41delete_files($dir, 2); 42?> 43===DONE=== 44--CLEAN-- 45<?php 46$dir = dirname(__FILE__) . '/scandir_variation10'; 47rmdir($dir); 48?> 49--EXPECTF-- 50SCANDIR_SORT_ASCENDING: 0 51SCANDIR_SORT_DESCENDING: 1 52SCANDIR_SORT_NONE: 2 53*** Testing scandir() : usage variations *** 54array(4) { 55 [0]=> 56 string(1) "." 57 [1]=> 58 string(2) ".." 59 [2]=> 60 string(9) "file1.tmp" 61 [3]=> 62 string(9) "file2.tmp" 63} 64array(4) { 65 [0]=> 66 string(9) "file2.tmp" 67 [1]=> 68 string(9) "file1.tmp" 69 [2]=> 70 string(2) ".." 71 [3]=> 72 string(1) "." 73} 74int(4) 75bool(true) 76bool(true) 77bool(true) 78bool(true) 79===DONE=== 80