How to delete a PHP object from its class?

2019-02-08 23:38发布

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 destroy/remove the object from within the class.

This is a PHP question. Something like unset($this); Is it possible and wise? And what is the right way to do it?

标签: php oop
7条回答
迷人小祖宗
2楼-- · 2019-02-09 00:27

Another approach is to make the delete-method static, which then could receive a PDO object and data, that determines what to delete. This way you don't need to initialise the object.

查看更多
登录 后发表回答