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