Summary of php destructor usage

Source: Internet
Author: User

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 );
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.