<?php
// Wrongly-encoded garbage, but base64_decode() will try anyway.
$bad = 'ABC123!@#$%';
$out = base64_decode($bad);
if ($out === FALSE) {
echo 'Failed without true as second parameter.'.PHP_EOL;
} else {
$len = strlen($out);
for ($i = 0;$i < $len;$i++) {
echo ord($out[$i]).' ';
}
echo PHP_EOL;
}
// You need to pass TRUE as a second parameter in order to make it fail loudly
$out2 = base64_decode($bad, TRUE);
if ($out2 === FALSE) {
echo 'Failed with true as second parameter.'.PHP_EOL;
} else {
$len = strlen($out);
for ($i = 0;$i < $len;$i++) {
echo ord($out[$i]).' ';
}
echo PHP_EOL;
}
0 16 181 219
Warning: base64_decode() expects exactly 1 parameter, 2 given in /in/JmLkY on line 20
0 16 181 219
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
0 16 181 219
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/JmLkY on line 16
PHP_EOL
Warning: base64_decode() expects exactly 1 parameter, 2 given in /in/JmLkY on line 20
0 16 181 219
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/JmLkY on line 31
PHP_EOL