1--TEST-- 2Test is_dir() function: usage variations - links 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) == 'WIN') { 6 die('skip Do not run on Windows'); 7} 8?> 9--FILE-- 10<?php 11/* Testing is_dir() with dir, soft & hard link to dir, 12 and with file, soft & hard link to file */ 13 14$file_path = __DIR__; 15 16echo "*** Testing is_dir() with dir and links to dir ***\n"; 17echo "-- With dir --\n"; 18$dirname = $file_path."/is_dir_variation2"; 19mkdir($dirname); 20var_dump( is_dir($dirname) ); 21clearstatcache(); 22 23echo "-- With symlink --\n"; 24symlink($file_path."/is_dir_variation2", $file_path."/is_dir_variation2_symlink"); 25var_dump( is_dir($file_path."/is_dir_variation2_symlink") ); //is_dir() resolves symlinks 26clearstatcache(); 27 28echo "-- With hardlink --"; 29link($file_path."/is_dir_variation2", $file_path."/is_dir_variation2_link"); //Not permitted to create hard-link to a dir 30var_dump( is_dir($file_path."/is_dir_variation2_link") ); 31clearstatcache(); 32 33echo "\n*** Testing is_dir() with file and links to a file ***\n"; 34echo "-- With file --\n"; 35$filename = $file_path."/is_dir_variation2.tmp"; 36fclose( fopen($filename, "w") ); 37var_dump( is_dir($filename) ); 38clearstatcache(); 39 40echo "-- With symlink --\n"; 41symlink($file_path."/is_dir_variation2.tmp", $file_path."/is_dir_variation2_symlink.tmp"); 42var_dump( is_dir($file_path."/is_dir_variation2_symlink.tmp") ); 43clearstatcache(); 44 45echo "-- With hardlink --\n"; 46link($file_path."/is_dir_variation2.tmp", $file_path."/is_dir_variation2_link.tmp"); 47var_dump( is_dir($file_path."/is_dir_variation2_link.tmp") ); 48clearstatcache(); 49 50echo "\n*** Done ***"; 51?> 52--CLEAN-- 53<?php 54$file_path = __DIR__; 55if(file_exists($file_path."/is_dir_variation2_symlink")) { 56 unlink($file_path."/is_dir_variation2_symlink"); 57} 58if(file_exists($file_path."/is_dir_variation2_symlink")) { 59 unlink($file_path."/is_dir_variation2_symlink"); 60} 61if(file_exists($file_path."/is_dir_variation2_symlink.tmp")) { 62 unlink($file_path."/is_dir_variation2_symlink.tmp"); 63} 64if(file_exists($file_path."/is_dir_variation2_link.tmp")) { 65 unlink($file_path."/is_dir_variation2_link.tmp"); 66} 67if(file_exists($file_path."/is_dir_variation2.tmp")) { 68 unlink($file_path."/is_dir_variation2.tmp"); 69} 70if(file_exists($file_path."/is_dir_variation2")) { 71 rmdir($file_path."/is_dir_variation2"); 72} 73?> 74--EXPECTF-- 75*** Testing is_dir() with dir and links to dir *** 76-- With dir -- 77bool(true) 78-- With symlink -- 79bool(true) 80-- With hardlink -- 81Warning: link(): %s in %s on line %d 82bool(false) 83 84*** Testing is_dir() with file and links to a file *** 85-- With file -- 86bool(false) 87-- With symlink -- 88bool(false) 89-- With hardlink -- 90bool(false) 91 92*** Done *** 93