1--TEST--
2Testing unlink() function : error conditions
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip.. only on Windows');
7}
8?>
9--FILE--
10<?php
11
12$file_path = __DIR__.DIRECTORY_SEPARATOR."unlinkErr私はガラスを食べられます";
13
14@mkdir($file_path);
15
16$filename = "$file_path/unlink_error.tmp";  // temp file name used here
17$fp = fopen($filename, "w");  // create file
18fclose($fp);
19
20// creating a context
21$context = stream_context_create();
22
23echo "*** Testing unlink() : error conditions ***\n";
24
25echo "\n-- Testing unlink() on invalid arguments --\n";
26// invalid arguments
27var_dump( unlink('') );  // $filename as empty string
28var_dump( file_exists('') );  // confirm file doesn't exist
29
30var_dump( unlink(NULL) );  // $filename as NULL
31var_dump( file_exists(NULL) );  // confirm file doesn't exist
32
33var_dump( unlink(false) );  // $filename as boolean false
34var_dump( file_exists(false) );  // confirm file doesn't exist
35
36
37echo "\n-- Testing unlink() on non-existent file --\n";
38var_dump( unlink(__DIR__."/non_existent_file.tmp") );
39
40echo "\n-- Testing unlink() on directory --\n";
41// temp directory used here
42$dirname = "$file_path/unlink_error";
43// create temp dir
44mkdir($dirname);
45// unlinking directory
46var_dump( unlink($dirname) );  // expected: false as unlink() does not work on dir
47
48echo "Done\n";
49?>
50--CLEAN--
51<?php
52unlink(__DIR__."/unlinkErr私はガラスを食べられます/unlink_error.tmp");
53rmdir(__DIR__."/unlinkErr私はガラスを食べられます/unlink_error");
54rmdir(__DIR__."/unlinkErr私はガラスを食べられます");
55?>
56--EXPECTF--
57*** Testing unlink() : error conditions ***
58
59-- Testing unlink() on invalid arguments --
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
69Warning: unlink(): %s in %s on line %d
70bool(false)
71bool(false)
72
73-- Testing unlink() on non-existent file --
74
75Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d
76bool(false)
77
78-- Testing unlink() on directory --
79
80Warning: unlink(%s/unlink_error): Is a directory in %s on line %d
81bool(false)
82Done
83