2
Test base64_decode() function : usage variations - unexpected types for arg 1
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
11
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
12
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
14
set_error_handler('test_error_handler');
16
echo "*** Testing base64_decode() : usage variations ***\n";
18
// Initialise function arguments not being substituted (if any)
21
//getting the resource
22
$file_handle = fopen(__FILE__, "r");
24
//get an unset variable
28
//array of values to iterate over
39
"10.1234567e10" => 10.1234567e10,
40
"10.7654321E-10" => 10.7654321E-10,
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'),
65
"stdClass object" => new stdclass(),
68
"undefined variable" => $undefined_var,
71
"unset variable" => $unset_var,
74
"resource" => $file_handle
77
// loop through each element of the array for str argument
79
foreach($values as $key=>$value) {
80
echo "\n-- Arg value $key --\n";
81
$output = base64_decode($value, $strict);
83
if (is_string($output)) {
84
var_dump(bin2hex($output));
93
*** Testing base64_decode() : usage variations ***
94
Error: 8 - Undefined variable: undefined_var, %s(%d)
95
Error: 8 - Undefined variable: unset_var, %s(%d)
103
-- Arg value 12345 --
106
-- Arg value -2345 --
112
-- Arg value -10.5 --
115
-- Arg value 10.1234567e10 --
116
string(18) "d74d76df8e7aef4d34"
118
-- Arg value 10.7654321E-10 --
124
-- Arg value array() --
125
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
128
-- Arg value array(0) --
129
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
132
-- Arg value array(1) --
133
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
136
-- Arg value array(1, 2) --
137
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
140
-- Arg value array('color' => 'red', 'item' => 'pen' --
141
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
153
-- Arg value false --
159
-- Arg value FALSE --
168
-- Arg value stdClass object --
169
Error: 2 - base64_decode() expects parameter 1 to be string, object given, %s(%d)
172
-- Arg value undefined variable --
175
-- Arg value unset variable --
178
-- Arg value resource --
179
Error: 2 - base64_decode() expects parameter 1 to be string, resource given, %s(%d)
b'\\ No newline at end of file'