1--TEST--
2Test base64_decode() function : usage variations  - unexpected types for arg 1
3--FILE--
4<?php
5/* Prototype  : proto string base64_decode(string str[, bool strict])
6 * Description: Decodes string using MIME base64 algorithm
7 * Source code: ext/standard/base64.c
8 * Alias to functions:
9 */
10
11function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
12	echo "Error: $err_no - $err_msg, $filename($linenum)\n";
13}
14set_error_handler('test_error_handler');
15
16echo "*** Testing base64_decode() : usage variations ***\n";
17
18// Initialise function arguments not being substituted (if any)
19$strict = true;
20
21//getting the resource
22$file_handle = fopen(__FILE__, "r");
23
24//get an unset variable
25$unset_var = 10;
26unset ($unset_var);
27
28//array of values to iterate over
29$values =  array (
30   	// int data
31	"0" =>  0,
32	"1" =>  1,
33	"12345" =>  12345,
34	"-2345"	=>  -2345,
35
36	// float data
37    "10.5" =>  10.5,
38	"-10.5" => -10.5,
39	"10.1234567e10" =>	10.1234567e10,
40	"10.7654321E-10" => 10.7654321E-10,
41	".5" => .5,
42
43    // array data
44    "array()" =>   array(),
45	"array(0)" =>  array(0),
46	"array(1)" =>  array(1),
47	"array(1, 2)" => array(1, 2),
48	"array('color' => 'red', 'item' => 'pen'" => array('color' => 'red', 'item' => 'pen'),
49
50	// null data
51	"NULL" => NULL,
52	"null" => null,
53
54	// boolean data
55	"true" => true,
56	"false" => false,
57	"TRUE" => TRUE,
58	"FALSE" => FALSE,
59
60	// empty data
61	"\"\"" => "",
62	"''" => '',
63
64	// object data
65	"stdClass object" => new stdclass(),
66
67	// undefined data
68    "undefined variable" => $undefined_var,
69
70	// unset data
71	"unset variable" => $unset_var,
72
73	// resource data
74	"resource" => $file_handle
75);
76
77// loop through each element of the array for str argument
78
79foreach($values as $key=>$value) {
80    echo "\n-- Arg value $key --\n";
81    $output =  base64_decode($value, $strict);
82
83	if (is_string($output)) {
84		var_dump(bin2hex($output));
85    } else {
86        var_dump($output);
87    }
88};
89
90?>
91===Done===
92--EXPECTF--
93*** Testing base64_decode() : usage variations ***
94Error: 8 - Undefined variable: undefined_var, %s(%d)
95Error: 8 - Undefined variable: unset_var, %s(%d)
96
97-- Arg value 0 --
98string(0) ""
99
100-- Arg value 1 --
101string(0) ""
102
103-- Arg value 12345 --
104string(6) "d76df8"
105
106-- Arg value -2345 --
107bool(false)
108
109-- Arg value 10.5 --
110bool(false)
111
112-- Arg value -10.5 --
113bool(false)
114
115-- Arg value 10.1234567e10 --
116string(18) "d74d76df8e7aef4d34"
117
118-- Arg value 10.7654321E-10 --
119bool(false)
120
121-- Arg value .5 --
122bool(false)
123
124-- Arg value array() --
125Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
126NULL
127
128-- Arg value array(0) --
129Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
130NULL
131
132-- Arg value array(1) --
133Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
134NULL
135
136-- Arg value array(1, 2) --
137Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
138NULL
139
140-- Arg value array('color' => 'red', 'item' => 'pen' --
141Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
142NULL
143
144-- Arg value NULL --
145string(0) ""
146
147-- Arg value null --
148string(0) ""
149
150-- Arg value true --
151string(0) ""
152
153-- Arg value false --
154string(0) ""
155
156-- Arg value TRUE --
157string(0) ""
158
159-- Arg value FALSE --
160string(0) ""
161
162-- Arg value "" --
163string(0) ""
164
165-- Arg value '' --
166string(0) ""
167
168-- Arg value stdClass object --
169Error: 2 - base64_decode() expects parameter 1 to be string, object given, %s(%d)
170NULL
171
172-- Arg value undefined variable --
173string(0) ""
174
175-- Arg value unset variable --
176string(0) ""
177
178-- Arg value resource --
179Error: 2 - base64_decode() expects parameter 1 to be string, resource given, %s(%d)
180NULL
181===Done===