Annotation of embedaddon/php/ext/standard/tests/general_functions/intval_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test intval() function : usage variation
3: --FILE--
4: <?php
5: /* Prototype : int intval(mixed var [, int base])
6: * Description: Get the integer value of a variable using the optional base for the conversion
7: * Source code: ext/standard/type.c
8: * Alias to functions:
9: */
10:
11: echo "*** Testing intval() : usage variation ***\n";
12:
13: // Define error handler
14: function 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: }
20: set_error_handler('test_error_handler');
21:
22: // Initialise function arguments not being substituted (if any)
23: $var = 1;
24:
25: //get an unset variable
26: $unset_var = 10;
27: unset ($unset_var);
28:
29: // define some classes
30: class classWithToString
31: {
32: public function __toString() {
33: return "Class A object";
34: }
35: }
36:
37: class classWithoutToString
38: {
39: }
40:
41: // heredoc string
42: $heredoc = <<<EOT
43: hello world
44: EOT;
45:
46: // add arrays
47: $index_array = array (1, 2, 3);
48: $assoc_array = array ('one' => 1, 'two' => 2);
49:
50: //array of values to iterate over
51: $inputs = array(
52:
53: // float data
54: 'float 10.5' => 10.5,
55: 'float -10.5' => -10.5,
56: 'float 12.3456789000e10' => 12.3456789000e10,
57: 'float -12.3456789000e10' => -12.3456789000e10,
58: 'float .5' => .5,
59:
60: // array data
61: 'empty array' => array(),
62: 'int indexed array' => $index_array,
63: 'associative array' => $assoc_array,
64: 'nested arrays' => array('foo', $index_array, $assoc_array),
65:
66: // null data
67: 'uppercase NULL' => NULL,
68: 'lowercase null' => null,
69:
70: // boolean data
71: 'lowercase true' => true,
72: 'lowercase false' =>false,
73: 'uppercase TRUE' =>TRUE,
74: 'uppercase FALSE' =>FALSE,
75:
76: // empty data
77: 'empty string DQ' => "",
78: 'empty string SQ' => '',
79:
80: // string data
81: 'string DQ' => "string",
82: 'string SQ' => 'string',
83: 'mixed case string' => "sTrInG",
84: 'heredoc' => $heredoc,
85:
86: // object data
87: 'instance of classWithToString' => new classWithToString(),
88: 'instance of classWithoutToString' => new classWithoutToString(),
89:
90: // undefined data
91: 'undefined var' => @$undefined_var,
92:
93: // unset data
94: 'unset var' => @$unset_var,
95: );
96:
97: // loop through each element of the array for base
98:
99: foreach($inputs as $key =>$value) {
100: echo "\n--$key--\n";
101: var_dump( intval($var, $value) );
102: };
103:
104: ?>
105: ===DONE===
106: --EXPECTF--
107: *** Testing intval() : usage variation ***
108:
109: --float 10.5--
110: int(1)
111:
112: --float -10.5--
113: int(1)
114:
115: --float 12.3456789000e10--
116: int(1)
117:
118: --float -12.3456789000e10--
119: int(1)
120:
121: --float .5--
122: int(1)
123:
124: --empty array--
125: Error: 2 - intval() expects parameter 2 to be long, array given, %s(%d)
126: NULL
127:
128: --int indexed array--
129: Error: 2 - intval() expects parameter 2 to be long, array given, %s(%d)
130: NULL
131:
132: --associative array--
133: Error: 2 - intval() expects parameter 2 to be long, array given, %s(%d)
134: NULL
135:
136: --nested arrays--
137: Error: 2 - intval() expects parameter 2 to be long, array given, %s(%d)
138: NULL
139:
140: --uppercase NULL--
141: int(1)
142:
143: --lowercase null--
144: int(1)
145:
146: --lowercase true--
147: int(1)
148:
149: --lowercase false--
150: int(1)
151:
152: --uppercase TRUE--
153: int(1)
154:
155: --uppercase FALSE--
156: int(1)
157:
158: --empty string DQ--
159: Error: 2 - intval() expects parameter 2 to be long, string given, %s(%d)
160: NULL
161:
162: --empty string SQ--
163: Error: 2 - intval() expects parameter 2 to be long, string given, %s(%d)
164: NULL
165:
166: --string DQ--
167: Error: 2 - intval() expects parameter 2 to be long, string given, %s(%d)
168: NULL
169:
170: --string SQ--
171: Error: 2 - intval() expects parameter 2 to be long, string given, %s(%d)
172: NULL
173:
174: --mixed case string--
175: Error: 2 - intval() expects parameter 2 to be long, string given, %s(%d)
176: NULL
177:
178: --heredoc--
179: Error: 2 - intval() expects parameter 2 to be long, string given, %s(%d)
180: NULL
181:
182: --instance of classWithToString--
183: Error: 2 - intval() expects parameter 2 to be long, object given, %s(%d)
184: NULL
185:
186: --instance of classWithoutToString--
187: Error: 2 - intval() expects parameter 2 to be long, object given, %s(%d)
188: NULL
189:
190: --undefined var--
191: int(1)
192:
193: --unset var--
194: int(1)
195: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>