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