什么时候在PHP中使用析构函数? [英] when to use destructor in php?
本文介绍了什么时候在PHP中使用析构函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
析构函数的主要目的是什么?
what is the main purpose of a destructor?
您能提供一些有关删除对象时我想运行的示例吗?
could you give any examples of what i might want to run when a object is deleted?
推荐答案
它使对象有机会准备被杀死.这可能意味着手动清理,状态持久性等.
It gives the object an opportunity to prepare to be killed. This could mean manual cleanup, state persistence, etc.
例如,模型可能希望将其所有当前属性保存回数据库中.
For example, a Model may want to save all of its current properties back into the database.
或者,数据库对象本身可能想要关闭用于与数据库服务器通信的套接字.
Or, a Database object itself might want to close the socket it is using to communicate to a database server.
这篇关于什么时候在PHP中使用析构函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文