Deserializing from JSON into PHP, with casting?

前端 未结 12 2026
既然无缘
既然无缘 2021-01-31 04:38

Suppose I have a User class with \'name\' and \'password\' properties, and a \'save\' method. When serializing an object of this class to JSON via json_encode, the method is pro

12条回答
  •  醉梦人生
    2021-01-31 04:47

    Have a look at this class I wrote:

    https://github.com/mindplay-dk/jsonfreeze/blob/master/mindplay/jsonfreeze/JsonSerializer.php

    It reserves a JSON object-property named '#type' to store the class-name, and it has some limitations that are described here:

    Serialize/unserialize PHP object-graph to JSON

提交回复
热议问题