1--TEST-- 2Test unlink() function : usage variation different types for context 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--FILE-- 6<?php 7/* Prototype : bool unlink(string filename[, context context]) 8 * Description: Delete a file 9 * Source code: ext/standard/file.c 10 * Alias to functions: 11 */ 12 13echo "*** Testing unlink() : usage variation different types for context ***\n"; 14 15// Define error handler 16function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { 17 if (error_reporting() != 0) { 18 // report non-silenced errors 19 echo "Error: $err_no - $err_msg, $filename($linenum)\n"; 20 } 21} 22set_error_handler('test_error_handler'); 23 24// Initialise function arguments not being substituted (if any) 25$filename = __FILE__.'tmp'; 26$fileRes = fopen(__FILE__, 'r'); 27 28//get an unset variable 29$unset_var = 10; 30unset ($unset_var); 31 32// define some classes 33class classWithToString 34{ 35 public function __toString() { 36 return "Class A object"; 37 } 38} 39 40class classWithoutToString 41{ 42} 43 44// heredoc string 45$heredoc = <<<EOT 46hello world 47EOT; 48 49// add arrays 50$index_array = array (1, 2, 3); 51$assoc_array = array ('one' => 1, 'two' => 2); 52 53//array of values to iterate over 54$inputs = array( 55 56 // int data 57 'int 0' => 0, 58 'int 1' => 1, 59 'int 12345' => 12345, 60 'int -12345' => -2345, 61 62 // float data 63 'float 10.5' => 10.5, 64 'float -10.5' => -10.5, 65 'float 12.3456789000e10' => 12.3456789000e10, 66 'float -12.3456789000e10' => -12.3456789000e10, 67 'float .5' => .5, 68 69 // array data 70 'empty array' => array(), 71 'int indexed array' => $index_array, 72 'associative array' => $assoc_array, 73 'nested arrays' => array('foo', $index_array, $assoc_array), 74 75 // null data 76 'uppercase NULL' => NULL, 77 'lowercase null' => null, 78 79 // boolean data 80 'lowercase true' => true, 81 'lowercase false' =>false, 82 'uppercase TRUE' =>TRUE, 83 'uppercase FALSE' =>FALSE, 84 85 // empty data 86 'empty string DQ' => "", 87 'empty string SQ' => '', 88 89 // string data 90 'string DQ' => "string", 91 'string SQ' => 'string', 92 'mixed case string' => "sTrInG", 93 'heredoc' => $heredoc, 94 95 // object data 96 'instance of classWithToString' => new classWithToString(), 97 'instance of classWithoutToString' => new classWithoutToString(), 98 99 // undefined data 100 'undefined var' => @$undefined_var, 101 102 // unset data 103 'unset var' => @$unset_var, 104 105 // file resource 106 'file resource' => $fileRes 107); 108 109// loop through each element of the array for context 110 111foreach($inputs as $key =>$value) { 112 echo "\n--$key--\n"; 113 touch($filename); // create if it doesn't exist 114 var_dump( unlink($filename, $value) ); 115}; 116 117if (file_exists($filename)) { 118 unlink($filename); 119} 120fclose($fileRes); 121 122?> 123===DONE=== 124--EXPECTF-- 125*** Testing unlink() : usage variation different types for context *** 126 127--int 0-- 128Error: 2 - unlink() expects parameter 2 to be resource, int given, %s(%d) 129bool(false) 130 131--int 1-- 132Error: 2 - unlink() expects parameter 2 to be resource, int given, %s(%d) 133bool(false) 134 135--int 12345-- 136Error: 2 - unlink() expects parameter 2 to be resource, int given, %s(%d) 137bool(false) 138 139--int -12345-- 140Error: 2 - unlink() expects parameter 2 to be resource, int given, %s(%d) 141bool(false) 142 143--float 10.5-- 144Error: 2 - unlink() expects parameter 2 to be resource, float given, %s(%d) 145bool(false) 146 147--float -10.5-- 148Error: 2 - unlink() expects parameter 2 to be resource, float given, %s(%d) 149bool(false) 150 151--float 12.3456789000e10-- 152Error: 2 - unlink() expects parameter 2 to be resource, float given, %s(%d) 153bool(false) 154 155--float -12.3456789000e10-- 156Error: 2 - unlink() expects parameter 2 to be resource, float given, %s(%d) 157bool(false) 158 159--float .5-- 160Error: 2 - unlink() expects parameter 2 to be resource, float given, %s(%d) 161bool(false) 162 163--empty array-- 164Error: 2 - unlink() expects parameter 2 to be resource, array given, %s(%d) 165bool(false) 166 167--int indexed array-- 168Error: 2 - unlink() expects parameter 2 to be resource, array given, %s(%d) 169bool(false) 170 171--associative array-- 172Error: 2 - unlink() expects parameter 2 to be resource, array given, %s(%d) 173bool(false) 174 175--nested arrays-- 176Error: 2 - unlink() expects parameter 2 to be resource, array given, %s(%d) 177bool(false) 178 179--uppercase NULL-- 180bool(true) 181 182--lowercase null-- 183bool(true) 184 185--lowercase true-- 186Error: 2 - unlink() expects parameter 2 to be resource, bool given, %s(%d) 187bool(false) 188 189--lowercase false-- 190Error: 2 - unlink() expects parameter 2 to be resource, bool given, %s(%d) 191bool(false) 192 193--uppercase TRUE-- 194Error: 2 - unlink() expects parameter 2 to be resource, bool given, %s(%d) 195bool(false) 196 197--uppercase FALSE-- 198Error: 2 - unlink() expects parameter 2 to be resource, bool given, %s(%d) 199bool(false) 200 201--empty string DQ-- 202Error: 2 - unlink() expects parameter 2 to be resource, string given, %s(%d) 203bool(false) 204 205--empty string SQ-- 206Error: 2 - unlink() expects parameter 2 to be resource, string given, %s(%d) 207bool(false) 208 209--string DQ-- 210Error: 2 - unlink() expects parameter 2 to be resource, string given, %s(%d) 211bool(false) 212 213--string SQ-- 214Error: 2 - unlink() expects parameter 2 to be resource, string given, %s(%d) 215bool(false) 216 217--mixed case string-- 218Error: 2 - unlink() expects parameter 2 to be resource, string given, %s(%d) 219bool(false) 220 221--heredoc-- 222Error: 2 - unlink() expects parameter 2 to be resource, string given, %s(%d) 223bool(false) 224 225--instance of classWithToString-- 226Error: 2 - unlink() expects parameter 2 to be resource, object given, %s(%d) 227bool(false) 228 229--instance of classWithoutToString-- 230Error: 2 - unlink() expects parameter 2 to be resource, object given, %s(%d) 231bool(false) 232 233--undefined var-- 234bool(true) 235 236--unset var-- 237bool(true) 238 239--file resource-- 240Error: 2 - unlink(): supplied resource is not a valid Stream-Context resource, %s(%d) 241bool(true) 242===DONE=== 243