Return to file_get_contents_variation6.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
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, "contents read"); 29: fclose($h); 30: 31: //get an unset variable 32: $unset_var = 10; 33: unset ($unset_var); 34: 35: // define some classes 36: class classWithToString 37: { 38: public function __toString() { 39: return "Class A object"; 40: } 41: } 42: 43: class classWithoutToString 44: { 45: } 46: 47: // heredoc string 48: $heredoc = <<<EOT 49: hello world 50: EOT; 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 .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 maxlen 108: 109: foreach($inputs as $key =>$value) { 110: echo "\n--$key--\n"; 111: var_dump( file_get_contents($absFile, false, null, 0, $value) ); 112: }; 113: 114: unlink($absFile); 115: 116: ?> 117: ===DONE=== 118: --EXPECTF-- 119: *** Testing file_get_contents() : usage variation *** 120: 121: --int 0-- 122: string(%d) "" 123: 124: --int 1-- 125: string(%d) "c" 126: 127: --int 12345-- 128: string(%d) "contents read" 129: 130: --int -12345-- 131: Error: 2 - file_get_contents(): length must be greater than or equal to zero, %s(%d) 132: bool(false) 133: 134: --float 10.5-- 135: string(%d) "contents r" 136: 137: --float -10.5-- 138: Error: 2 - file_get_contents(): length must be greater than or equal to zero, %s(%d) 139: bool(false) 140: 141: --float .5-- 142: string(%d) "" 143: 144: --empty array-- 145: Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d) 146: NULL 147: 148: --int indexed array-- 149: Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d) 150: NULL 151: 152: --associative array-- 153: Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d) 154: NULL 155: 156: --nested arrays-- 157: Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d) 158: NULL 159: 160: --uppercase NULL-- 161: string(%d) "" 162: 163: --lowercase null-- 164: string(%d) "" 165: 166: --lowercase true-- 167: string(%d) "c" 168: 169: --lowercase false-- 170: string(%d) "" 171: 172: --uppercase TRUE-- 173: string(%d) "c" 174: 175: --uppercase FALSE-- 176: string(%d) "" 177: 178: --empty string DQ-- 179: Error: 2 - file_get_contents() expects parameter 5 to be long, string given, %s(%d) 180: NULL 181: 182: --empty string SQ-- 183: Error: 2 - file_get_contents() expects parameter 5 to be long, string given, %s(%d) 184: NULL 185: 186: --string DQ-- 187: Error: 2 - file_get_contents() expects parameter 5 to be long, string given, %s(%d) 188: NULL 189: 190: --string SQ-- 191: Error: 2 - file_get_contents() expects parameter 5 to be long, string given, %s(%d) 192: NULL 193: 194: --mixed case string-- 195: Error: 2 - file_get_contents() expects parameter 5 to be long, string given, %s(%d) 196: NULL 197: 198: --heredoc-- 199: Error: 2 - file_get_contents() expects parameter 5 to be long, string given, %s(%d) 200: NULL 201: 202: --instance of classWithToString-- 203: Error: 2 - file_get_contents() expects parameter 5 to be long, object given, %s(%d) 204: NULL 205: 206: --instance of classWithoutToString-- 207: Error: 2 - file_get_contents() expects parameter 5 to be long, object given, %s(%d) 208: NULL 209: 210: --undefined var-- 211: string(%d) "" 212: 213: --unset var-- 214: string(%d) "" 215: ===DONE===