PHP5 object model
PHP5 has a single inheritance, restricted access, an object model that can be overloaded. This chapter will discuss the "inheritance", containing the parent-child relationship between the class later. In addition, PHP supports restrictivity to attributes and methods Access. You can declare that member is Private, not allowing external class access. Finally, PHP allows a subclass to overload members from its parent class. The object model of php5 is different from any other data type, by reference Pass. PHP does not require you to expand and return to objects by reference (Reference). In this chapter, the reference object model will be described in detail. It is the most important new feature in PHP5. With a more direct object model, With additional advantages: increasing efficiency, less memory, and has greater flexibility. In the first few versions of PHP, the script defaults to copy the object. Now the php5 mobile handle, require less time. Script execution The increase in efficiency is due to avoiding unnecessary replication. While the object system brought complexity, it also brings the income of performing efficiency. At the same time, reduced replication means that less memory is occupied, you can leave more memory For other operations, this also enhances efficiency. Zand Engine 2 has greater flexibility. A happy development is to allow destructor - executing a class method before the target destroy. This is also very beneficial for the use of memory. Let PHP clearly know when there is no reference to an object, assigns the empty memory to other purposes.
supplement:
PHP5 memory management
Object
PHP5 uses the Zend Engine II, and the object is stored in an independent structure Object Store, and is not stored in ZVAL like other general variables (stored in ZVAL as the object and general variables in PHP4). The pointer to the object is stored in ZVAL instead of content (value). We do not need to copy data when we copy an object or pass an object as a parameter to a function. Only the same object pointer and notification from another ZVAL now point to the Object Store now. Since the object itself is located in the Object Store, any change we do will affect all ZVAL structures held by the object pointer --- Manifestation is that any change in the target object will affect the source object. This makes the PHP object seem to be passed by reference (Reference), so the objects in PHP defaults to pass through "reference", and you no longer need to use & to declare it in PHP4.
Garbage collection mechanism
Some languages, most typical C, need you explicitly request allocation to allocate inscribed portability when you create a data structure. Once you assign to memory, you can store information in variables. At the same time, you also need to release the memory while ending using variables, which allows the machine to empty to other variables to avoid lighting memory.
PHP can automatically perform memory management, clear the object that is no longer needed. PHP uses a reference count (Reference Counting) mechanism. Each object contains a reference counter, and each Reference is connected to the object, and the counter adds 1. When Reference is left to the living space or set to NULL, the counter minus 1. When a reference counter of an object is zero, PHP knows that you will no longer need to use this object, release the memory space it occupied.
E.g: