Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP unserialize problem

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?

like image 859
John Avatar asked Feb 13 '09 14:02

John


2 Answers

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

like image 197
Greg Avatar answered Oct 07 '22 08:10

Greg


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.

like image 25
SilentGhost Avatar answered Oct 07 '22 08:10

SilentGhost