1--TEST-- 2Testing unlink() function : error conditions 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) == 'WIN') { 6 die('skip.. only on Linux'); 7} 8?> 9--FILE-- 10<?php 11 12$file_path = __DIR__; 13 14$filename = "$file_path/unlink_error.tmp"; // temp file name used here 15$fp = fopen($filename, "w"); // create file 16fclose($fp); 17 18// creating a context 19$context = stream_context_create(); 20 21echo "*** Testing unlink() : error conditions ***\n"; 22 23echo "\n-- Testing unlink() on invalid arguments --\n"; 24// invalid arguments 25var_dump( unlink('') ); // $filename as empty string 26var_dump( file_exists('') ); // confirm file doesn't exist 27 28var_dump( unlink(false) ); // $filename as boolean false 29var_dump( file_exists(false) ); // confirm file doesn't exist 30 31echo "\n-- Testing unlink() on non-existent file --\n"; 32var_dump( unlink(__DIR__."/non_existent_file.tmp") ); 33 34echo "\n-- Testing unlink() on directory --\n"; 35// temp directory used here 36$dirname = "$file_path/unlink_error"; 37// create temp dir 38mkdir($dirname); 39// unlinking directory 40var_dump( unlink($dirname) ); // expected: false as unlink() does not work on dir 41 42echo "Done\n"; 43?> 44--CLEAN-- 45<?php 46unlink(__DIR__."/unlink_error.tmp"); 47rmdir(__DIR__."/unlink_error"); 48?> 49--EXPECTF-- 50*** Testing unlink() : error conditions *** 51 52-- Testing unlink() on invalid arguments -- 53 54Warning: unlink(): %s in %s on line %d 55bool(false) 56bool(false) 57 58Warning: unlink(): %s in %s on line %d 59bool(false) 60bool(false) 61 62-- Testing unlink() on non-existent file -- 63 64Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d 65bool(false) 66 67-- Testing unlink() on directory -- 68 69Warning: unlink(%s/unlink_error): %s in %s on line %d 70bool(false) 71Done 72