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