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条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题