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