1--TEST--
2Test base64_decode() function : usage variations   - unexpected types for arg 2
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$str = 'aGVsbG8gd29ybGQh!';
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 strict argument
78
79foreach($values as $key=>$value) {
80    echo "\n-- Arg value $key --\n";
81    var_dump(base64_decode($str, $value));
82};
83
84?>
85===Done===
86--EXPECTF--
87*** Testing base64_decode() : usage variations ***
88Error: 8 - Undefined variable: undefined_var, %s(%d)
89Error: 8 - Undefined variable: unset_var, %s(%d)
90
91-- Arg value 0 --
92string(12) "hello world!"
93
94-- Arg value 1 --
95bool(false)
96
97-- Arg value 12345 --
98bool(false)
99
100-- Arg value -2345 --
101bool(false)
102
103-- Arg value 10.5 --
104bool(false)
105
106-- Arg value -10.5 --
107bool(false)
108
109-- Arg value 10.1234567e10 --
110bool(false)
111
112-- Arg value 10.7654321E-10 --
113bool(false)
114
115-- Arg value .5 --
116bool(false)
117
118-- Arg value array() --
119Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(%d)
120NULL
121
122-- Arg value array(0) --
123Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(%d)
124NULL
125
126-- Arg value array(1) --
127Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(%d)
128NULL
129
130-- Arg value array(1, 2) --
131Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(%d)
132NULL
133
134-- Arg value array('color' => 'red', 'item' => 'pen' --
135Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(%d)
136NULL
137
138-- Arg value NULL --
139string(12) "hello world!"
140
141-- Arg value null --
142string(12) "hello world!"
143
144-- Arg value true --
145bool(false)
146
147-- Arg value false --
148string(12) "hello world!"
149
150-- Arg value TRUE --
151bool(false)
152
153-- Arg value FALSE --
154string(12) "hello world!"
155
156-- Arg value "" --
157string(12) "hello world!"
158
159-- Arg value '' --
160string(12) "hello world!"
161
162-- Arg value stdClass object --
163Error: 2 - base64_decode() expects parameter 2 to be boolean, object given, %s(%d)
164NULL
165
166-- Arg value undefined variable --
167string(12) "hello world!"
168
169-- Arg value unset variable --
170string(12) "hello world!"
171
172-- Arg value resource --
173Error: 2 - base64_decode() expects parameter 2 to be boolean, resource given, %s(%d)
174NULL
175===Done===