This article mainly introduces the usage of php destructor in detail. If you need a friend, you can refer to it and hope to help you briefly, the Destructor is used to complete special work when the object is closed. For example, I wrote a previous example to open a file while instantiating it. But when will it be closed? Close it when it is used up, so when the Destructor closes it directly, or when the Destructor is performed, we write some processed data into the database. At this time, we can consider using the destructor to complete the process, before the Destructor is complete, these object attributes still exist and are only used for internal access, therefore, you can safely perform any aftermath analysis functions related to objects, instead of releasing the object's memory, instead, you can use it to guide the internal existence of php to be released when the user needs to release some additional memory. Finally, php uses
The Code is as follows:
Class x
{
Function _ construct ()
{
$ This-> file = fopen ('path', 'A ');
}
Function _ destruct ()
{
Fclose ($ this-> file );
}
}