Construction method and destructor method in PHP

Source: Internet
Author: User

First, the construction method:

The constructor method is the first method that is automatically called by the object after the object is created, so it is common to use construction methods to perform initialization of some objects.

The construction method in PHP cannot be overloaded for the following reasons:

1, the name of the construction method is fixed, in PHP can not declare the same name of two functions;

However, you can implement the ability to construct method overloads in other object-oriented programming languages by using default parameters when declaring construction methods.

Second, the Destruction method

A destructor is the last method that an object is automatically called by an object before it is destroyed, so a destructor is often used to complete cleanup of objects before they are destroyed.

Case where the object was destroyed:

1. When the object in the heap memory loses access to its reference, such as the reference is given a null value;

2, the page runs the end, the object loses the application.

Construction method and destructor method in PHP

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.