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