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$use_include_path = false;
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      // int data
64      'int 0' => 0,
65      'int 1' => 1,
66      'int 12345' => 12345,
67      'int -12345' => -2345,
68
69      // float data
70      'float 10.5' => 10.5,
71      'float -10.5' => -10.5,
72      'float 12.3456789000e10' => 12.3456789000e10,
73      'float -12.3456789000e10' => -12.3456789000e10,
74      'float .5' => .5,
75
76      // array data
77      'empty array' => array(),
78      'int indexed array' => $index_array,
79      'associative array' => $assoc_array,
80      'nested arrays' => array('foo', $index_array, $assoc_array),
81
82      // null data
83      'uppercase NULL' => NULL,
84      'lowercase null' => null,
85
86      // boolean data
87      'lowercase true' => true,
88      'lowercase false' =>false,
89      'uppercase TRUE' =>TRUE,
90      'uppercase FALSE' =>FALSE,
91
92      // empty data
93      'empty string DQ' => "",
94      'empty string SQ' => '',
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 mode
111
112foreach($inputs as $key =>$value) {
113      echo "\n--$key--\n";
114      var_dump( gzopen($filename, $value, $use_include_path) );
115};
116
117fclose($fp);
118
119?>
120===DONE===
121--EXPECTF--
122*** Testing gzopen() : usage variation ***
123
124--int 0--
125Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
126bool(false)
127
128--int 1--
129Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
130bool(false)
131
132--int 12345--
133Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
134bool(false)
135
136--int -12345--
137Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
138bool(false)
139
140--float 10.5--
141Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
142bool(false)
143
144--float -10.5--
145Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
146bool(false)
147
148--float 12.3456789000e10--
149Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
150bool(false)
151
152--float -12.3456789000e10--
153Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
154bool(false)
155
156--float .5--
157Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
158bool(false)
159
160--empty array--
161Error: 2 - gzopen() expects parameter 2 to be string, array given, %s(%d)
162NULL
163
164--int indexed array--
165Error: 2 - gzopen() expects parameter 2 to be string, array given, %s(%d)
166NULL
167
168--associative array--
169Error: 2 - gzopen() expects parameter 2 to be string, array given, %s(%d)
170NULL
171
172--nested arrays--
173Error: 2 - gzopen() expects parameter 2 to be string, array given, %s(%d)
174NULL
175
176--uppercase NULL--
177Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
178bool(false)
179
180--lowercase null--
181Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
182bool(false)
183
184--lowercase true--
185Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
186bool(false)
187
188--lowercase false--
189Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
190bool(false)
191
192--uppercase TRUE--
193Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
194bool(false)
195
196--uppercase FALSE--
197Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
198bool(false)
199
200--empty string DQ--
201Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
202bool(false)
203
204--empty string SQ--
205Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
206bool(false)
207
208--instance of classWithToString--
209Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
210bool(false)
211
212--instance of classWithoutToString--
213Error: 2 - gzopen() expects parameter 2 to be string, object given, %s(%d)
214NULL
215
216--undefined var--
217Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
218bool(false)
219
220--unset var--
221Error: 2 - gzopen(%s/004.txt.gz): failed to open stream: %s, %s(%d)
222bool(false)
223
224--resource--
225Error: 2 - gzopen() expects parameter 2 to be string, resource given, %s(%d)
226NULL
227===DONE===
228