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