1--TEST--
2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link name stored in an array/object
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip no symlinks on Windows');
7}
8?>
9--FILE--
10<?php
11/* Prototype: bool symlink ( string $target, string $link );
12   Description: creates a symbolic link to the existing target with the specified name link
13
14   Prototype: bool is_link ( string $filename );
15   Description: Tells whether the given file is a symbolic link.
16
17   Prototype: bool link ( string $target, string $link );
18   Description: Create a hard link
19
20   Prototype: int linkinfo ( string $path );
21   Description: Gets information about a link
22*/
23
24/* Variation 1 : Creating links across directories where linkname is stored as an object and array member */
25
26// creating temp directory which will contain temp file and links created
27$file_path = dirname(__FILE__);
28$dirname = "$file_path/symlink_link_linkinfo_is_link_variation1/test/home";
29mkdir($dirname, 0777, true);
30
31// creating temp file; links are created to this file later on
32$filename = "$file_path/symlink_link_linkinfo_is_link_variation1/symlink_link_linkinfo_is_link_variation1.tmp";
33$fp = fopen($filename, "w");
34fclose($fp);
35
36echo "*** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members in an object ***\n";
37class object_temp {
38  var $linkname;
39  function object_temp($link) {
40    $this->linkname = $link;
41  }
42}
43
44$obj = new object_temp("$dirname/symlink_link_linkinfo_is_link_link.tmp");
45/* Testing on soft links */
46echo "\n-- Working with soft links --\n";
47// creating soft link
48var_dump( symlink($filename, $obj->linkname) );
49// check if the link exists
50var_dump( linkinfo($obj->linkname) );
51// check if link is soft link
52var_dump( is_link($obj->linkname) );
53// delete the link created
54unlink($obj->linkname);
55// clear the cache
56clearstatcache();
57
58/* Testing on hard links */
59echo "\n-- Working with hard links --\n";
60// creating hard link
61var_dump( link($filename, $obj->linkname) );
62// check if the link exists
63var_dump( linkinfo($obj->linkname) );
64// check if link is soft link; expected: false as the link is a hardlink
65var_dump( is_link($obj->linkname) );
66// delete the link created
67unlink($obj->linkname);
68// clear the cache
69clearstatcache();
70
71echo "\n*** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members of an array ***\n";
72
73$link_arr = array("$dirname/symlink_link_linkinfo_is_link_link.tmp");
74
75/* Testing on soft links */
76echo "\n-- Working with soft links --\n";
77// creating soft link
78var_dump( symlink($filename, $link_arr[0]) );
79// check if the link exist
80var_dump( linkinfo($link_arr[0]) );
81// check if link is soft link
82var_dump( is_link($link_arr[0]) );
83// delete the link created
84unlink($link_arr[0]);
85// clear the cache
86clearstatcache();
87
88/* Testing on hard links */
89echo "\n-- Working with hard links --\n";
90// creating hard link
91var_dump( link($filename, $link_arr[0]) );
92// check if the link exist
93var_dump( linkinfo($link_arr[0]) );
94// check if link is soft link; expected: false as this is a hardlink
95var_dump( is_link($link_arr[0]) );
96// delete the links created
97unlink($link_arr[0]);
98// clear the cache
99clearstatcache();
100
101echo "Done\n";
102?>
103--CLEAN--
104<?php
105$file_path = dirname(__FILE__);
106$dirname = "$file_path/symlink_link_linkinfo_is_link_variation1";
107unlink("$dirname/symlink_link_linkinfo_is_link_variation1.tmp");
108rmdir("$dirname/test/home");
109rmdir("$dirname/test");
110rmdir($dirname);
111?>
112--EXPECTF--
113*** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members in an object ***
114
115-- Working with soft links --
116bool(true)
117int(%d)
118bool(true)
119
120-- Working with hard links --
121bool(true)
122int(%d)
123bool(false)
124
125*** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members of an array ***
126
127-- Working with soft links --
128bool(true)
129int(%d)
130bool(true)
131
132-- Working with hard links --
133bool(true)
134int(%d)
135bool(false)
136Done
137