How to delete a PHP object from its class?

后端 未结 7 793
攒了一身酷
攒了一身酷 2021-01-02 06:51

I know that for some that might sound stupid, but I was thinking if I hava a delete() method in a class that removes all the object data (from DB and file system), how can I

7条回答
  •  -上瘾入骨i
    2021-01-02 06:59

    This depends on how you've structured your class.

    If you're following DTO/DAO patterns, your data would be separate from your model and you can simply remove the DTO. If you're not, simply unsetting the data part of the class should do it.

    But in actual terms, I think this is unnecessary since PHP will automatically cleanup at the end of the request. Unless you're working on a giant object that takes up massive amounts of memory, and it's a long process it's not really worth the effort.

提交回复
热议问题