douchuang1861 2018-12-21 17:28
浏览 123
已采纳

使用不匹配属性的新类名反序列化类

We have serialized classes stored in our database that we are trying to deserialize with new psr 4 class names. When we run the deserialize function the class is not created properly.

The old and new classes are the same the only thing that has really changed is that the names are different from psr 0 class names to psr 4 classes. When we deserialize we are making sure to use class_alias to point the old classes stored in the serialized code to the new classes. We are not getting any errors when we deserialize but the class properties are not setup properly.

For example we are working with the serialized class Company_Shipping. We alias that class before to Company\Shipping, but when we dump the object we get the properties

private '_method' => null

private '_method' (Company_Shipping) => string 'ground' (length=6)

We should be just getting

private '_method' => string 'ground' (length=6)

So one, is there a way to access the second private property with the old class name in brackets? If I could do that I might be able to transfer the properties in the __wake method, but I can't figure out how to access them. However, if someone knows how to fix this deserialization that would be great too.

  • 写回答

2条回答 默认 最新

  • dsadsadsa1231 2018-12-21 18:54
    关注

    This is a great learning opportunity about why private is overkill. If the properties were merely protected you could have declared:

    class Company_Shipping extends Company\Shipping {}
    

    and unserialized with no problem.

    At this point I would say that your best option is to leave a copy of the legacy Company_Shipping object code in your application, write some code to convert from Company_Shipping to Company\Shipping, [which again will be more difficult than needs be because private] and then either explicitly re-encode all of your stored objects to the new format or plug in various shims to detect and convert them on the fly.

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

报告相同问题?

悬赏问题

  • ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?