1--TEST--
2Test file function : variation - various absolute and relative paths
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--FILE--
6<?php
7echo "*** Testing file() : variation ***\n";
8$mainDir = "fileVar8.dir";
9$subDir = "fileVar8Sub";
10$absMainDir = __DIR__."/".$mainDir;
11mkdir($absMainDir);
12$absSubDir = $absMainDir."/".$subDir;
13mkdir($absSubDir);
14
15$old_dir_path = getcwd();
16chdir(__DIR__);
17
18$allDirs = array(
19  // absolute paths
20  "$absSubDir/",
21  "$absSubDir/../".$subDir,
22  "$absSubDir//.././".$subDir,
23  "$absSubDir/../../".$mainDir."/./".$subDir,
24  "$absSubDir/..///".$subDir."//..//../".$subDir,
25  "$absSubDir/BADDIR",
26
27  // relative paths
28  $mainDir."/".$subDir,
29  $mainDir."//".$subDir,
30   $mainDir."///".$subDir,
31  "./".$mainDir."/../".$mainDir."/".$subDir,
32  "BADDIR",
33
34);
35
36$filename = 'FileGetContentsVar7.tmp';
37$absFile = $absSubDir.'/'.$filename;
38$h = fopen($absFile,"w");
39fwrite($h, "contents read");
40fclose($h);
41
42for($i = 0; $i<count($allDirs); $i++) {
43  $j = $i+1;
44  $dir = $allDirs[$i];
45  echo "\n-- Iteration $j --\n";
46  var_dump(file($dir."/".$filename));
47}
48
49unlink($absFile);
50chdir($old_dir_path);
51rmdir($absSubDir);
52rmdir($absMainDir);
53
54echo "\n*** Done ***\n";
55?>
56--EXPECTF--
57*** Testing file() : variation ***
58
59-- Iteration 1 --
60array(1) {
61  [0]=>
62  string(13) "contents read"
63}
64
65-- Iteration 2 --
66array(1) {
67  [0]=>
68  string(13) "contents read"
69}
70
71-- Iteration 3 --
72array(1) {
73  [0]=>
74  string(13) "contents read"
75}
76
77-- Iteration 4 --
78array(1) {
79  [0]=>
80  string(13) "contents read"
81}
82
83-- Iteration 5 --
84
85Warning: file(%sfileVar8.dir/fileVar8Sub/..///fileVar8Sub//..//../fileVar8Sub/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
86bool(false)
87
88-- Iteration 6 --
89
90Warning: file(%sfileVar8.dir/fileVar8Sub/BADDIR/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
91bool(false)
92
93-- Iteration 7 --
94array(1) {
95  [0]=>
96  string(13) "contents read"
97}
98
99-- Iteration 8 --
100array(1) {
101  [0]=>
102  string(13) "contents read"
103}
104
105-- Iteration 9 --
106array(1) {
107  [0]=>
108  string(13) "contents read"
109}
110
111-- Iteration 10 --
112array(1) {
113  [0]=>
114  string(13) "contents read"
115}
116
117-- Iteration 11 --
118
119Warning: file(BADDIR/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
120bool(false)
121
122*** Done ***
123