I have a PHP function:
function unserialize_recursive($data, $i = 0) {
$unserialized = unserialize($data);
if ($unserialized) {
$i++;
}
if (!is_string($unserialized) || unserialize($unserialized) === FALSE) {
/* placeholder - see explanation below */
return array($i, $unserialized);
} elseif (unserialize($unserialized) !== FALSE) {
unserialize_recursive($unserialized, $i);
}
return FALSE;
}
I call this function with:
$data = unserialize_recursive($serialized_string);
var_dump($data);
But the output of var_dump($data)
is bool(false)
.
However, if I add var_dump($unserialized)
in the position of the text /* placeholder - see explanation below */
, I get the expected output.
So why can I not return that variable ($unserialized
)? If I use gettype()
on it at that point in the function, it returns array
.
I'm using Netbeans and all the syntax highlighting indicates the code is properly formed with no typos. I'm baffled. Have I missed something really obvious?