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(NULL) ); // $filename as NULL 29var_dump( file_exists(NULL) ); // confirm file doesn't exist 30 31var_dump( unlink(false) ); // $filename as boolean false 32var_dump( file_exists(false) ); // confirm file doesn't exist 33 34echo "\n-- Testing unlink() on non-existent file --\n"; 35var_dump( unlink(__DIR__."/non_existent_file.tmp") ); 36 37echo "\n-- Testing unlink() on directory --\n"; 38// temp directory used here 39$dirname = "$file_path/unlink_error"; 40// create temp dir 41mkdir($dirname); 42// unlinking directory 43var_dump( unlink($dirname) ); // expected: false as unlink() does not work on dir 44 45echo "Done\n"; 46?> 47--CLEAN-- 48<?php 49unlink(__DIR__."/unlink_error.tmp"); 50rmdir(__DIR__."/unlink_error"); 51?> 52--EXPECTF-- 53*** Testing unlink() : error conditions *** 54 55-- Testing unlink() on invalid arguments -- 56 57Warning: unlink(): %s in %s on line %d 58bool(false) 59bool(false) 60 61Warning: unlink(): %s in %s on line %d 62bool(false) 63bool(false) 64 65Warning: unlink(): %s in %s on line %d 66bool(false) 67bool(false) 68 69-- Testing unlink() on non-existent file -- 70 71Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d 72bool(false) 73 74-- Testing unlink() on directory -- 75 76Warning: unlink(%s/unlink_error): %s in %s on line %d 77bool(false) 78Done 79