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/* Variation 7 : Create soft/hard link to itself */ 13 14// temp file used 15$file_path = __DIR__; 16$dir = "$file_path/symlink_link_linkinfo_is_link_variation7"; 17$filename = "$dir/symlink_link_linkinfo_is_link_variation7.tmp"; 18// link name used 19$linkname = "$dir/symlink_link_linkinfo_is_link_link_variation7.tmp"; 20// temp dirname used 21$dirname = "$dir/home/test"; 22mkdir($dirname, 0755, true); 23 24// create file 25$fp = fopen($filename, "w"); 26fclose($fp); 27 28echo "*** Create soft link to file and then to itself ***\n"; 29// create soft link to $filename 30var_dump( symlink($filename, $linkname) ); 31// create another link to $linkname 32var_dump( symlink($linkname, $linkname) ); 33// delete link 34unlink($linkname); 35 36echo "\n*** Create soft link to directory and then to itself ***\n"; 37// create soft link to $dirname 38var_dump( symlink($dirname, $linkname) ); 39// create another link to $dirname 40var_dump( symlink($linkname, $linkname) ); 41// delete link 42if (PHP_OS_FAMILY === 'Windows') { 43 rmdir($linkname); 44} else { 45 unlink($linkname); 46} 47 48echo "\n*** Create hard link to file and then to itself ***\n"; 49// create hard link to $filename 50var_dump( link($filename, $linkname) ); 51// create another link to $linkname 52var_dump( link($linkname, $linkname) ); 53// delete link 54unlink($linkname); 55 56echo "Done\n"; 57?> 58--CLEAN-- 59<?php 60$file_path = __DIR__; 61$dir = "$file_path/symlink_link_linkinfo_is_link_variation7"; 62$filename = "$dir/symlink_link_linkinfo_is_link_variation7.tmp"; 63unlink($filename); 64rmdir("$dir/home/test"); 65rmdir("$dir/home"); 66rmdir($dir); 67?> 68--EXPECTF-- 69*** Create soft link to file and then to itself *** 70bool(true) 71 72Warning: symlink(): File exists in %s on line %d 73bool(false) 74 75*** Create soft link to directory and then to itself *** 76bool(true) 77 78Warning: symlink(): File exists in %s on line %d 79bool(false) 80 81*** Create hard link to file and then to itself *** 82bool(true) 83 84Warning: link(): File exists in %s on line %d 85bool(false) 86Done 87