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