views:

1036

answers:

2

How come unserialize isn't restoring my array? See code below..

// prints a:1:{s:8:"txn_type";s:32:"recurring_payment_profile_cancel";}
echo $item['response']; 

// prints nothing
print_r(unserialize($item['response']));

I understand why the print_r($response) gives me nothing

** edit - I noticed this

Notice: unserialize() [function.unserialize]: Error at offset 6 of 2797 bytes in /home/reitinve/public_html/action/doc.php on line 13

What does that mean?

+1  A: 

works for me just fine. are you sure that $item['response'] is a string? yeah, seems like leading whitespaces.

and on your dev server php never should give you 'nothing'. it should be configured to produce all errors, warnings and notices. also you can use http://php.net/var_dump instead of print_r as it give you more information.

SilentGhost
If unserialize's parameter is not a string, it will show a warning.
Christopher W. Allen-Poole
it shows notice if strings starts with space too.
SilentGhost
true, but the default configuration won't show notices
Greg
+2  A: 

Is it possible $item['response'] contains some whitespace before or after it?

Check strlen($item['response']) gives you 61.

Edit: It seems to work with whitespace at the end, but whitespace at the start will make it fail to unserialize.

Edit: that error message means either you have a LOT of whitespace (almost 2kb of it), or $item['response'] is being changed between the echo and the unserialize

Greg
That's my guess.
Christopher W. Allen-Poole
i tried putting a trim like unserialize(trim($item['response'])). The trim should have removed white spaces right?
John
Yes. The string you say is echo'd is 61 bytes, but PHP says you're trying to unserialize 2797 bytes, so something is going on...
Greg