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