Section 2 object model [2]

Source: Internet
Author: User
Section 2 object model [2] PHP5 has a single-inherited, restricted-access, and reloaded object model. this chapter will discuss inheritance in detail later, including the parent-child relationship between classes. in addition, PHP supports restricted access to attributes and methods. you can declare that the members are private and do not allow external Class access. finally, PHP allows a subclass to reload members from its parent class.

File: // haohappy note: PHP4 does not have private, and only public. private is good for better encapsulation.

The object model of PHP5 treats an object as different from any other data type and is passed through reference. PHP does not require you to pass and return objects through reference explicitly. at the end of this chapter, we will elaborate on the handle-based object model. it is the most important new feature in PHP5.

With a more direct object model, the handle-based system has the following advantages: higher efficiency, less memory occupation, and greater flexibility.

In the first few versions of PHP, the script copies objects by default. now, PHP5 only moves the handle, which takes less time. the script execution efficiency is improved because unnecessary copying is avoided. while the object system brings complexity, it also brings the benefit of execution efficiency. at the same time, reducing replication means that less memory is occupied and more memory can be set aside for other operations, which also improves the efficiency.

File: // haohappy Note: based on the handle, the two objects can point to the same memory, which reduces the copy operation and memory usage.

Zand engine 2 has greater flexibility. a happy development is to allow the destructor to execute a class method before the object is destroyed. this is also very good for the use of memory, so that PHP can clearly know when there is no object reference, and allocate the empty memory to other purposes.

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.