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/* Variation 1 : Creating links across directories where linkname is stored as an object and array member */ 13 14// creating temp directory which will contain temp file and links created 15$file_path = __DIR__; 16$dirname = "$file_path/symlink_link_linkinfo_is_link_variation1/test/home"; 17mkdir($dirname, 0777, true); 18 19// creating temp file; links are created to this file later on 20$filename = "$file_path/symlink_link_linkinfo_is_link_variation1/symlink_link_linkinfo_is_link_variation1.tmp"; 21$fp = fopen($filename, "w"); 22fclose($fp); 23 24echo "*** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members in an object ***\n"; 25class object_temp { 26 var $linkname; 27 function __construct($link) { 28 $this->linkname = $link; 29 } 30} 31 32$obj = new object_temp("$dirname/symlink_link_linkinfo_is_link_link.tmp"); 33/* Testing on soft links */ 34echo "\n-- Working with soft links --\n"; 35// creating soft link 36var_dump( symlink($filename, $obj->linkname) ); 37// check if the link exists 38$linkinfo = linkinfo($obj->linkname); 39var_dump( is_int($linkinfo) && $linkinfo !== -1 ); 40// check if link is soft link 41var_dump( is_link($obj->linkname) ); 42// delete the link created 43unlink($obj->linkname); 44// clear the cache 45clearstatcache(); 46 47/* Testing on hard links */ 48echo "\n-- Working with hard links --\n"; 49// creating hard link 50var_dump( link($filename, $obj->linkname) ); 51// check if the link exists 52$linkinfo = linkinfo($obj->linkname); 53var_dump( is_int($linkinfo) && $linkinfo !== -1 ); 54// check if link is soft link; expected: false as the link is a hardlink 55var_dump( is_link($obj->linkname) ); 56// delete the link created 57unlink($obj->linkname); 58// clear the cache 59clearstatcache(); 60 61echo "\n*** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members of an array ***\n"; 62 63$link_arr = array("$dirname/symlink_link_linkinfo_is_link_link.tmp"); 64 65/* Testing on soft links */ 66echo "\n-- Working with soft links --\n"; 67// creating soft link 68var_dump( symlink($filename, $link_arr[0]) ); 69// check if the link exist 70$linkinfo = linkinfo($link_arr[0]); 71var_dump( is_int($linkinfo) && $linkinfo !== -1 ); 72// check if link is soft link 73var_dump( is_link($link_arr[0]) ); 74// delete the link created 75unlink($link_arr[0]); 76// clear the cache 77clearstatcache(); 78 79/* Testing on hard links */ 80echo "\n-- Working with hard links --\n"; 81// creating hard link 82var_dump( link($filename, $link_arr[0]) ); 83// check if the link exist 84$linkinfo = linkinfo($link_arr[0]); 85var_dump( is_int($linkinfo) && $linkinfo !== -1 ); 86// check if link is soft link; expected: false as this is a hardlink 87var_dump( is_link($link_arr[0]) ); 88// delete the links created 89unlink($link_arr[0]); 90// clear the cache 91clearstatcache(); 92 93echo "Done\n"; 94?> 95--CLEAN-- 96<?php 97$file_path = __DIR__; 98$dirname = "$file_path/symlink_link_linkinfo_is_link_variation1"; 99unlink("$dirname/symlink_link_linkinfo_is_link_variation1.tmp"); 100rmdir("$dirname/test/home"); 101rmdir("$dirname/test"); 102rmdir($dirname); 103?> 104--EXPECT-- 105*** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members in an object *** 106 107-- Working with soft links -- 108bool(true) 109bool(true) 110bool(true) 111 112-- Working with hard links -- 113bool(true) 114bool(true) 115bool(false) 116 117*** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members of an array *** 118 119-- Working with soft links -- 120bool(true) 121bool(true) 122bool(true) 123 124-- Working with hard links -- 125bool(true) 126bool(true) 127bool(false) 128Done 129