Section II--PHP5 object Model--Classes and Objects in PHP5 [2]

Source: Internet
Author: User
Tags execution inheritance object model php programming reference
object|php5| Objects | = This article is for Haohappy read <<core PHP programming>>
| = Notes from the chapter classes and objects
| = translation-oriented + personal experience
| = Please do not reprint to avoid any unnecessary trouble that may occur, thank you
| = Welcome to criticize, hope and all PHP enthusiasts to progress together!
+-------------------------------------------------------------------------------+
*/

Section II--PHP5 object model

PHP5 has a single-inheritance, restricted access to the object model that can be overloaded. "Inheritance", which is discussed in detail later in this chapter, contains the parent-child relationships between classes. In addition, PHP supports restrictive access to properties and methods. You can declare that members are private and do not allow external class access. Finally, PHP allows a subclass to overload members from its parent class.

Haohappy Note: There is no private in PHP4, only public.private is good for better implementation of encapsulation.

The PHP5 object model considers objects to be passed by reference as distinct from any other data type. PHP does not require you to pass and return objects explicitly by reference (reference). The object model based on the handle will be elaborated in detail at the end of this chapter. It is the most important new feature in PHP5.

With a more direct object model, a handle based system has additional advantages: increased efficiency, less memory footprint, and greater flexibility.

In the first few versions of PHP, the script replicates objects by default. Now PHP5 only moves the handle, which takes less time. The improvement in script execution efficiency is due to the avoidance of unnecessary replication. While the object system brings complexity, it also brings the benefit of execution efficiency. At the same time, reducing replication means taking in less memory, allowing more memory to be left to other operations, which also increases efficiency.

Haohappy Note: Based on the handle, that is, two objects can point to the same memory, both reduce the copy action, and reduce the memory footprint.

The Zand Engine 2 has greater flexibility. One pleasing development is allowing for deconstruction--Executing a class method before the object is destroyed. This is also good for using memory, so that PHP clearly knows when there are no references to objects and allocates the empty memory to other uses.

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.