dongruan6001 2011-12-15 08:27
浏览 93
已采纳

php unserialize在不同机器上的工作方式不同

I have an array that has been serialized by php, the result is:

unserialize('a:2:{s:13:"custom_basket";a:1:{i:280583837398;a:4:{s:12:"product_name";s:0:"";s:8:"quantity";s:1:"1";s:5:"price";d:38.649999999999999;s:11:"description";a:7:{s:2:"id";s:12:"280583837398";s:3:"sku";s:0:"";s:4:"site";s:2:"UK";s:12:"condition_id";s:4:"1000";s:14:"transaction_id";s:12:"773563256018";s:8:"platform";s:4:"eBay";s:18:"order_line_item_id";s:25:"280583837398-773563256018";}}}s:6:"basket";a:0:{}}')

When I use my machine running php 5.3.5 I get:

Notice: unserialize() [function.unserialize]: Error at offset 46 of 405 bytes

When the dude next to me runs it on his machine running 5.3.6 he gets the array back out. Our server that runs php 5.3.4 also successfully unserializes the array.

The error that I get points to the first key in the second array i:280583837398 if I change this too s:12:"280583837398" my machine can now unserialize the array successfully.

Does anyone have any idea why this is happening. I have no idea if it is the php version, I just noticed that I had a different version to the two successful machines so thought it worth mentioning.

I am running MAMP PRO on Snow Leopard if that helps.

  • 写回答

2条回答 默认 最新

  • duanou9739 2011-12-15 09:38
    关注

    Not sure if it's the version or not, but maybe the different versions handle ints differently. It seems like you understand s means a string of x length, hence s:12 is a string of length 12. But if php is trying to parse that as a 32 bit int, then it may fail.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?