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