Home >Web Front-end >JS Tutorial >Summary of specific usage of php destructor_javascript skills

Summary of specific usage of php destructor_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:55:531040browse

To put it simply, the destructor is used to complete special work when the object is closed. For example, in the above example I wrote, a file is opened at the same time as it is instantiated, but when will it be closed? Just close it after use. Therefore, the destructor directly closes it, or during destruction, we write some of the processed data into the database. In this case, we can consider using the destructor to complete it. Before the destructor is completed, these object attributes remain exists and is only used for internal access, so you can safely do any aftermath work related to the object The destructor is not to release the object's own memory, but to use it when the user needs to release some additional memory. To guide PHP where the memory that needs to be released is. Finally, PHP uses

during destruction. Copy the code . The code is as follows:

class x
{
function __construct()
{
$this->file = fopen('path', 'a');
}
function __destruct()
{
fclose($this->file);
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn