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 = 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-- \$path = './level_one': --\n";
29var_dump(chdir($base_dir_path));
30var_dump($dh = opendir("./$level_one_dir_name"));
31clean_dh($dh);
32
33echo "\n-- \$path = 'level_one/level_two': --\n";
34var_dump(chdir($base_dir_path));
35var_dump($dh = opendir("$level_one_dir_name/$level_two_dir_name"));
36clean_dh($dh);
37
38echo "\n-- \$path = '..': --\n";
39var_dump($dh = opendir('..'));
40clean_dh($dh);
41
42echo "\n-- \$path = 'level_two', '.': --\n";
43var_dump(chdir($level_two_dir_path));
44var_dump($dh = opendir('.'));
45clean_dh($dh);
46
47echo "\n-- \$path = '../': --\n";
48var_dump($dh = opendir('../'));
49clean_dh($dh);
50
51echo "\n-- \$path = './': --\n";
52var_dump(chdir($level_two_dir_path));
53var_dump($dh = opendir('./'));
54clean_dh($dh);
55
56echo "\n-- \$path = '../../'level_one': --\n";
57var_dump(chdir($level_two_dir_path));
58var_dump($dh = opendir("../../$level_one_dir_name"));
59clean_dh($dh);
60
61/*
62 * function to remove directory handle before re-using variable name in test
63 * and to ensure directory is not in use at CLEAN section so can me removed
64 */
65function clean_dh($dh){
66	if (is_resource($dh)) {
67		closedir($dh);
68	}
69	unset($dh);
70}
71?>
72===DONE===
73--CLEAN--
74<?php
75$file_path = dirname(__FILE__);
76rmdir("$file_path/level_one/level_two");
77rmdir("$file_path/level_one");
78?>
79--EXPECTF--
80*** Testing opendir() : usage variation ***
81
82-- $path = './level_one': --
83bool(true)
84resource(%d) of type (stream)
85
86-- $path = 'level_one/level_two': --
87bool(true)
88resource(%d) of type (stream)
89
90-- $path = '..': --
91resource(%d) of type (stream)
92
93-- $path = 'level_two', '.': --
94bool(true)
95resource(%d) of type (stream)
96
97-- $path = '../': --
98resource(%d) of type (stream)
99
100-- $path = './': --
101bool(true)
102resource(%d) of type (stream)
103
104-- $path = '../../'level_one': --
105bool(true)
106resource(%d) of type (stream)
107===DONE===
108