1--TEST--
2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - try link to self
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 7 : Create soft/hard link to itself */
26
27// temp file used
28$file_path = __DIR__;
29$dir = "$file_path/symlink_link_linkinfo_is_link_variation7";
30$filename = "$dir/symlink_link_linkinfo_is_link_variation7.tmp";
31// link name used
32$linkname = "$dir/symlink_link_linkinfo_is_link_link_variation7.tmp";
33// temp dirname used
34$dirname = "$dir/home/test";
35mkdir($dirname, 0755, true);
36
37// create file
38$fp = fopen($filename, "w");
39fclose($fp);
40
41echo "*** Create soft link to file and then to itself ***\n";
42// create soft link to $filename
43var_dump( symlink($filename, $linkname) );
44// create another link to $linkname
45var_dump( symlink($linkname, $linkname) );
46// delete link
47unlink($linkname);
48
49echo "\n*** Create soft link to directory and then to itself ***\n";
50// create soft link to $dirname
51var_dump( symlink($dirname, $linkname) );
52// create another link to $dirname
53var_dump( symlink($linkname, $linkname) );
54// delete link
55if (PHP_OS_FAMILY === 'Windows') {
56    rmdir($linkname);
57} else {
58    unlink($linkname);
59}
60
61echo "\n*** Create hard link to file and then to itself ***\n";
62// create hard link to $filename
63var_dump( link($filename, $linkname) );
64// create another link to $linkname
65var_dump( link($linkname, $linkname) );
66// delete link
67unlink($linkname);
68
69echo "Done\n";
70?>
71--CLEAN--
72<?php
73$file_path = __DIR__;
74$dir = "$file_path/symlink_link_linkinfo_is_link_variation7";
75$filename = "$dir/symlink_link_linkinfo_is_link_variation7.tmp";
76unlink($filename);
77rmdir("$dir/home/test");
78rmdir("$dir/home");
79rmdir($dir);
80?>
81--EXPECTF--
82*** Create soft link to file and then to itself ***
83bool(true)
84
85Warning: symlink(): File exists in %s on line %d
86bool(false)
87
88*** Create soft link to directory and then to itself ***
89bool(true)
90
91Warning: symlink(): File exists in %s on line %d
92bool(false)
93
94*** Create hard link to file and then to itself ***
95bool(true)
96
97Warning: link(): File exists in %s on line %d
98bool(false)
99Done
100