1--TEST-- 2Test dir() function : usage variations - operate on previously opened directory 3--FILE-- 4<?php 5/* 6 * Prototype : object dir(string $directory[, resource $context]) 7 * Description: Directory class with properties, handle and class and methods read, rewind and close 8 * Source code: ext/standard/dir.c 9 */ 10 11/* 12 * Testing the behavior of dir() function by trying to open a 13 * directory which is already open. 14 */ 15 16echo "*** Testing dir() : operate on previously opened directory ***\n"; 17 18// include the file.inc for Function: function create_files() 19include( dirname(__FILE__)."/../file/file.inc"); 20 21// create the temporary directory 22$file_path = dirname(__FILE__); 23$dir_path = $file_path."/dir_variation4"; 24@mkdir($dir_path); 25 26// create files within the temporary directory 27create_files($dir_path, 3, "alphanumeric", 0755, 1, "w", "dir_variation4"); 28 29// open the directory 30$d = dir($dir_path); 31var_dump( $d ); 32 33// open the same directory again without closing it 34$e = dir($dir_path); 35var_dump( $e ); 36 37echo "-- reading directory contents with previous handle --\n"; 38var_dump( $d->read() ); // with previous handle 39 40echo "-- reading directory contents with current handle --\n"; 41var_dump( $e->read() ); // with current handle 42 43// delete temporary files 44delete_files($dir_path, 3, "dir_variation4"); 45echo "Done"; 46?> 47--CLEAN-- 48<?php 49$file_path = dirname(__FILE__); 50$dir_path = $file_path."/dir_variation4"; 51 52rmdir($dir_path); 53?> 54--EXPECTF-- 55*** Testing dir() : operate on previously opened directory *** 56object(Directory)#%d (2) { 57 ["path"]=> 58 string(%d) "%s/dir_variation4" 59 ["handle"]=> 60 resource(%d) of type (stream) 61} 62object(Directory)#%d (2) { 63 ["path"]=> 64 string(%d) "%s/dir_variation4" 65 ["handle"]=> 66 resource(%d) of type (stream) 67} 68-- reading directory contents with previous handle -- 69string(%d) "%s" 70-- reading directory contents with current handle -- 71string(%d) "%s" 72Done 73