Object-Oriented 3

Source: Internet
Author: User

We need to perform some tasks when creating and destroying objects. For example, when creating an object, assigning a value to a property, closing the data connection when the object is destroyed, and so on, requires constructors and destructors.

constructor Function

    • Constructors can accept parameters and be able to assign values to object properties when creating an object
    • Constructors can call class methods or other functions
    • Constructors can call constructors of other classes

Destructors

    • Destructors are calls that are automatically called when an object is destroyed and cannot be displayed.
    • Destructors cannot take parameters.

Destructors may be called (but not necessarily) in the following situations:

    • After the PHP page has finished loading;
    • Unset () class;
    • When a variable reference points to another object or value;

The access modifier can be used to decorate the object's methods, and the rules are the same:

Public: The method can be accessed at any scope.

Protected: A method can only be accessed from a member of a class or an inherited class.

Private: The method can only be accessed from one member of the class and cannot be accessed from members of the inheriting class. As with attributes, private methods can be redefined in an inherited class. Each class can see only the private methods it defines itself.

Object-Oriented 3

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.