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

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?