1--TEST-- 2Test chdir() function : usage variations - relative paths 3--FILE-- 4<?php 5/* Prototype : bool chdir(string $directory) 6 * Description: Change the current directory 7 * Source code: ext/standard/dir.c 8 */ 9 10/* 11 * Test chdir() with variations of relative paths 12 */ 13 14echo "*** Testing chdir() : usage variations ***\n"; 15 16$base_dir_path = dirname(__FILE__); 17 18$level_one_dir_name = "level_one"; 19$level_one_dir_path = "$base_dir_path/$level_one_dir_name"; 20 21$level_two_dir_name = "level_two"; 22$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name"; 23 24// create directories 25mkdir($level_one_dir_path); 26mkdir($level_two_dir_path); 27 28echo "\n-- \$directory = './level_one': --\n"; 29var_dump(chdir($base_dir_path)); 30var_dump(chdir("./$level_one_dir_name")); 31var_dump(getcwd()); 32 33echo "\n-- \$directory = 'level_one/level_two': --\n"; 34var_dump(chdir($base_dir_path)); 35var_dump(chdir("$level_one_dir_name/$level_two_dir_name")); 36var_dump(getcwd()); 37 38echo "\n-- \$directory = '..': --\n"; 39var_dump(chdir('..')); 40var_dump(getcwd()); 41 42echo "\n-- \$directory = 'level_two', '.': --\n"; 43var_dump(chdir($level_two_dir_path)); 44var_dump(chdir('.')); 45var_dump(getcwd()); 46 47echo "\n-- \$directory = '../': --\n"; 48var_dump(chdir('../')); 49var_dump(getcwd()); 50 51echo "\n-- \$directory = './': --\n"; 52var_dump(chdir($level_two_dir_path)); 53var_dump(chdir('./')); 54var_dump(getcwd()); 55 56echo "\n-- \$directory = '../../'level_one': --\n"; 57var_dump(chdir($level_two_dir_path)); 58var_dump(chdir("../../$level_one_dir_name")); 59var_dump(getcwd()); 60 61?> 62===DONE=== 63--CLEAN-- 64<?php 65$file_path = dirname(__FILE__); 66rmdir("$file_path/level_one/level_two"); 67rmdir("$file_path/level_one"); 68?> 69--EXPECTF-- 70*** Testing chdir() : usage variations *** 71 72-- $directory = './level_one': -- 73bool(true) 74bool(true) 75string(%d) "%slevel_one" 76 77-- $directory = 'level_one/level_two': -- 78bool(true) 79bool(true) 80string(%d) "%slevel_one%elevel_two" 81 82-- $directory = '..': -- 83bool(true) 84string(%d) "%slevel_one" 85 86-- $directory = 'level_two', '.': -- 87bool(true) 88bool(true) 89string(%d) "%slevel_one%elevel_two" 90 91-- $directory = '../': -- 92bool(true) 93string(%d) "%slevel_one" 94 95-- $directory = './': -- 96bool(true) 97bool(true) 98string(%d) "%slevel_one%elevel_two" 99 100-- $directory = '../../'level_one': -- 101bool(true) 102bool(true) 103string(%d) "%slevel_one" 104===DONE=== 105