How to serialize object that has closures inside properties?

后端 未结 4 1327
面向向阳花
面向向阳花 2021-01-14 05:57

if I do serialize($obj), I get:

Serialization of \'Closure\' is not allowed

Is there any way these closures can be

4条回答
  •  梦毁少年i
    2021-01-14 06:32

    To serialize properties of an object while ignoring closures :

    $properties = array_map(function ($property) {
        try {
            return serialize($property);
        } catch (\Exception $e) {
            return null;
        }
    }, get_object_vars($this));
    

提交回复
热议问题