2 /* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
3 * Description: Open a file or a URL and return a file pointer
4 * Source code: ext/standard/file.c
8 function readFile2($file) :mixed{
9 $h = fopen($file, 'r');
15 function appendFile($file) :mixed{
16 $h = fopen($file, 'a+');
17 fwrite($h, ' again!');
24 function writeFile($file) :mixed{
25 $h = fopen($file, 'w');
26 fwrite($h, 'Goodbye World');
30 <<__EntryPoint
>> function main(): void
{
31 $tmpDir = sys_get_temp_dir().'/'.'fopenVar19.Dir';
32 $realFilename = basename(__FILE__
).'.real';
33 $sortFilename = basename(__FILE__
).'.soft';
34 $hardFilename = basename(__FILE__
).'.hard';
35 $linkOfLink = basename(__FILE__
).'.soft2';
37 echo "*** Testing fopen() : variation ***\n";
40 $oldDirPath = getcwd();
43 $h = fopen($realFilename, "w");
44 fwrite($h, "Hello World");
47 symlink($realFilename, $sortFilename);
48 symlink($sortFilename, $linkOfLink);
49 link($realFilename, $hardFilename);
53 echo "*** testing reading of links ***\n";
55 readFile2($sortFilename);
57 readFile2($hardFilename);
59 readFile2($linkOfLink);
61 echo "*** test appending to links ***\n";
63 appendFile($sortFilename);
65 appendFile($hardFilename);
67 appendFile($linkOfLink);
69 echo "*** test overwriting links ***\n";
71 writeFile($sortFilename);
73 writeFile($hardFilename);
75 writeFile($linkOfLink);
78 unlink($sortFilename);
79 unlink($hardFilename);
80 unlink($realFilename);