In short, the Destructor are used to complete special work when the object is closed. For example, I wrote the upper case that a file is opened while instantiating, but when will it be closed, close it when you use it, so the Destructor closes it directly, or when the Destructor is performed, we can 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
Copy codeThe Code is as follows:
Class x
{
Function _ construct ()
{
$ This-> file = fopen ('path', 'A ');
}
Function _ destruct ()
{
Fclose ($ this-> file );
}
}