Deep cloning an object : Clone vs Serialize

前端 未结 2 1238
既然无缘
既然无缘 2021-01-25 02:40

I have this function duplicateCourseAction whose goal is to ... duplicate a Course object

public function duplicateCourseAction(Request $request) {
    if ($this         


        
2条回答
  •  鱼传尺愫
    2021-01-25 03:04

    You can control what exactly gets cloned by overriding the __clone() method in your Course entity. You can set id to null and clone referenced objects if you need a deep copy.

    The serialization/unserialization feels like a hack, so I recommend against using it.

提交回复
热议问题