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