1--TEST-- 2Test readfile() function : usage variation 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--FILE-- 6<?php 7/* Prototype : int readfile(string filename [, bool use_include_path[, resource context]]) 8 * Description: Output a file or a URL 9 * Source code: ext/standard/file.c 10 * Alias to functions: 11 */ 12 13echo "*** Testing readfile() : usage variation ***\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 = 'readFileVar5.tmp'; 26$use_include_path = false; 27$h = fopen($filename,'wb'); 28fwrite($h, "testing readfile"); 29fclose($h); 30 31//get an unset variable 32$unset_var = 10; 33unset ($unset_var); 34 35// define some classes 36class classWithToString 37{ 38 public function __toString() { 39 return "Class A object"; 40 } 41} 42 43class classWithoutToString 44{ 45} 46 47// heredoc string 48$heredoc = <<<EOT 49hello world 50EOT; 51 52// add arrays 53$index_array = array (1, 2, 3); 54$assoc_array = array ('one' => 1, 'two' => 2); 55 56//array of values to iterate over 57$inputs = array( 58 59 // int data 60 'int 0' => 0, 61 'int 1' => 1, 62 'int 12345' => 12345, 63 'int -12345' => -2345, 64 65 // float data 66 'float 10.5' => 10.5, 67 'float -10.5' => -10.5, 68 'float 12.3456789000e10' => 12.3456789000e10, 69 'float -12.3456789000e10' => -12.3456789000e10, 70 'float .5' => .5, 71 72 // array data 73 'empty array' => array(), 74 'int indexed array' => $index_array, 75 'associative array' => $assoc_array, 76 'nested arrays' => array('foo', $index_array, $assoc_array), 77 78 // null data 79 'uppercase NULL' => NULL, 80 'lowercase null' => null, 81 82 // boolean data 83 'lowercase true' => true, 84 'lowercase false' =>false, 85 'uppercase TRUE' =>TRUE, 86 'uppercase FALSE' =>FALSE, 87 88 // empty data 89 'empty string DQ' => "", 90 'empty string SQ' => '', 91 92 // string data 93 'string DQ' => "string", 94 'string SQ' => 'string', 95 'mixed case string' => "sTrInG", 96 'heredoc' => $heredoc, 97 98 // object data 99 'instance of classWithToString' => new classWithToString(), 100 'instance of classWithoutToString' => new classWithoutToString(), 101 102 // undefined data 103 'undefined var' => @$undefined_var, 104 105 // unset data 106 'unset var' => @$unset_var, 107); 108 109// loop through each element of the array for use_include_path 110 111foreach($inputs as $key =>$value) { 112 echo "\n--$key--\n"; 113 $res = readfile($filename, $value); 114 if ($res == false) { 115 echo "File not read\n"; 116 } 117 else { 118 echo "\n"; 119 } 120}; 121 122unlink($filename); 123 124?> 125===DONE=== 126--EXPECTF-- 127*** Testing readfile() : usage variation *** 128 129--int 0-- 130testing readfile 131 132--int 1-- 133testing readfile 134 135--int 12345-- 136testing readfile 137 138--int -12345-- 139testing readfile 140 141--float 10.5-- 142testing readfile 143 144--float -10.5-- 145testing readfile 146 147--float 12.3456789000e10-- 148testing readfile 149 150--float -12.3456789000e10-- 151testing readfile 152 153--float .5-- 154testing readfile 155 156--empty array-- 157Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d) 158File not read 159 160--int indexed array-- 161Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d) 162File not read 163 164--associative array-- 165Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d) 166File not read 167 168--nested arrays-- 169Error: 2 - readfile() expects parameter 2 to be boolean, array given, %s(%d) 170File not read 171 172--uppercase NULL-- 173testing readfile 174 175--lowercase null-- 176testing readfile 177 178--lowercase true-- 179testing readfile 180 181--lowercase false-- 182testing readfile 183 184--uppercase TRUE-- 185testing readfile 186 187--uppercase FALSE-- 188testing readfile 189 190--empty string DQ-- 191testing readfile 192 193--empty string SQ-- 194testing readfile 195 196--string DQ-- 197testing readfile 198 199--string SQ-- 200testing readfile 201 202--mixed case string-- 203testing readfile 204 205--heredoc-- 206testing readfile 207 208--instance of classWithToString-- 209Error: 2 - readfile() expects parameter 2 to be boolean, object given, %s(%d) 210File not read 211 212--instance of classWithoutToString-- 213Error: 2 - readfile() expects parameter 2 to be boolean, object given, %s(%d) 214File not read 215 216--undefined var-- 217testing readfile 218 219--unset var-- 220testing readfile 221===DONE=== 222