1--TEST--
2Test ip2long() function : usage variation 1
3--FILE--
4<?php
5/* Prototype  : int ip2long(string ip_address)
6 * Description: Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address
7 * Source code: ext/standard/basic_functions.c
8 * Alias to functions:
9 */
10
11echo "*** Testing ip2long() : usage variation ***\n";
12
13// Define error handler
14function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
15	if (error_reporting() != 0) {
16		// report non-silenced errors
17		echo "Error: $err_no - $err_msg, $filename($linenum)\n";
18	}
19}
20set_error_handler('test_error_handler');
21
22// Initialise function arguments not being substituted (if any)
23
24//get an unset variable
25$unset_var = 10;
26unset ($unset_var);
27
28// define some classes
29class classWithToString
30{
31	public function __toString() {
32		return "Class A object";
33	}
34}
35
36class classWithoutToString
37{
38}
39
40// heredoc string
41$heredoc = <<<EOT
42hello world
43EOT;
44
45// add arrays
46$index_array = array (1, 2, 3);
47$assoc_array = array ('one' => 1, 'two' => 2);
48
49// resource
50$res = fopen(__FILE__,'r');
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      // resource
99      'resource' => $res,
100);
101
102// loop through each element of the array for ip_address
103
104foreach($inputs as $key =>$value) {
105      echo "\n--$key--\n";
106      var_dump( ip2long($value) );
107};
108
109fclose($res);
110
111?>
112===DONE===
113--EXPECTF--
114*** Testing ip2long() : usage variation ***
115
116--int 0--
117bool(false)
118
119--int 1--
120bool(false)
121
122--int 12345--
123bool(false)
124
125--int -12345--
126bool(false)
127
128--float 10.5--
129bool(false)
130
131--float -10.5--
132bool(false)
133
134--float 12.3456789000e10--
135bool(false)
136
137--float -12.3456789000e10--
138bool(false)
139
140--float .5--
141bool(false)
142
143--empty array--
144Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
145NULL
146
147--int indexed array--
148Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
149NULL
150
151--associative array--
152Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
153NULL
154
155--nested arrays--
156Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
157NULL
158
159--uppercase NULL--
160bool(false)
161
162--lowercase null--
163bool(false)
164
165--lowercase true--
166bool(false)
167
168--lowercase false--
169bool(false)
170
171--uppercase TRUE--
172bool(false)
173
174--uppercase FALSE--
175bool(false)
176
177--empty string DQ--
178bool(false)
179
180--empty string SQ--
181bool(false)
182
183--instance of classWithToString--
184bool(false)
185
186--instance of classWithoutToString--
187Error: 2 - ip2long() expects parameter 1 to be string, object given, %s(%d)
188NULL
189
190--undefined var--
191bool(false)
192
193--unset var--
194bool(false)
195
196--resource--
197Error: 2 - ip2long() expects parameter 1 to be string, resource given, %s(%d)
198NULL
199===DONE===
200