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