1--TEST-- 2Test opendir() function : usage variations - different relative paths 3--FILE-- 4<?php 5/* Prototype : mixed opendir(string $path[, resource $context]) 6 * Description: Open a directory and return a dir_handle 7 * Source code: ext/standard/dir.c 8 */ 9 10/* 11 * Test opendir() with different relative paths as $path argument 12 */ 13 14echo "*** Testing opendir() : usage variation ***\n"; 15 16$base_dir_path = __DIR__ . '/opendir_variation4'; 17@mkdir($base_dir_path); 18 19$level_one_dir_name = "level_one"; 20$level_one_dir_path = "$base_dir_path/$level_one_dir_name"; 21 22$level_two_dir_name = "level_two"; 23$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name"; 24 25// create directories 26mkdir($level_one_dir_path); 27mkdir($level_two_dir_path); 28 29echo "\n-- \$path = './level_one': --\n"; 30var_dump(chdir($base_dir_path)); 31var_dump($dh = opendir("./$level_one_dir_name")); 32clean_dh($dh); 33 34echo "\n-- \$path = 'level_one/level_two': --\n"; 35var_dump(chdir($base_dir_path)); 36var_dump($dh = opendir("$level_one_dir_name/$level_two_dir_name")); 37clean_dh($dh); 38 39echo "\n-- \$path = '..': --\n"; 40var_dump($dh = opendir('..')); 41clean_dh($dh); 42 43echo "\n-- \$path = 'level_two', '.': --\n"; 44var_dump(chdir($level_two_dir_path)); 45var_dump($dh = opendir('.')); 46clean_dh($dh); 47 48echo "\n-- \$path = '../': --\n"; 49var_dump($dh = opendir('../')); 50clean_dh($dh); 51 52echo "\n-- \$path = './': --\n"; 53var_dump(chdir($level_two_dir_path)); 54var_dump($dh = opendir('./')); 55clean_dh($dh); 56 57echo "\n-- \$path = '../../'level_one': --\n"; 58var_dump(chdir($level_two_dir_path)); 59var_dump($dh = opendir("../../$level_one_dir_name")); 60clean_dh($dh); 61 62/* 63 * function to remove directory handle before re-using variable name in test 64 * and to ensure directory is not in use at CLEAN section so can me removed 65 */ 66function clean_dh($dh){ 67 if (is_resource($dh)) { 68 closedir($dh); 69 } 70 unset($dh); 71} 72?> 73===DONE=== 74--CLEAN-- 75<?php 76$base_dir_path = __DIR__ . '/opendir_variation4'; 77rmdir("$base_dir_path/level_one/level_two"); 78rmdir("$base_dir_path/level_one"); 79rmdir($base_dir_path); 80?> 81--EXPECTF-- 82*** Testing opendir() : usage variation *** 83 84-- $path = './level_one': -- 85bool(true) 86resource(%d) of type (stream) 87 88-- $path = 'level_one/level_two': -- 89bool(true) 90resource(%d) of type (stream) 91 92-- $path = '..': -- 93resource(%d) of type (stream) 94 95-- $path = 'level_two', '.': -- 96bool(true) 97resource(%d) of type (stream) 98 99-- $path = '../': -- 100resource(%d) of type (stream) 101 102-- $path = './': -- 103bool(true) 104resource(%d) of type (stream) 105 106-- $path = '../../'level_one': -- 107bool(true) 108resource(%d) of type (stream) 109===DONE=== 110