Home >Backend Development >PHP Tutorial >Section 2 Object Model [2]_PHP Tutorial
PHP5 has a single-inherited, restricted-access, overloadable object model. "Inheritance," discussed in detail later in this chapter, involves parent-child relationships between classes. In addition, PHP supports restrictions on properties and methods. Access. You can declare members as private, disallowing access from external classes. Finally, PHP allows a subclass to overload members from its parent class.
file://haohappyNote: There is no private in PHP4, Only public.private is good for better encapsulation.
PHP5’s object model treats objects as different from any other data type and is passed by reference. PHP does not require you to express it by reference. Sexually passing and returning objects. The handle-based object model will be explained in detail at the end of this chapter. It is the most important new feature in PHP5.
With a more direct object model, the handle-based system has additional Advantages: Improved efficiency, takes up less memory, and has greater flexibility.
In previous versions of PHP, scripts copied 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 copying. While the object system brings complexity, it also brings benefits in execution efficiency. At the same time, reducing copying means occupying less memory and leaving more space. More memory is used for other operations, which also improves efficiency.
file://haohappy Note: Based on handles, that means two objects can point to the same piece of memory, which not only reduces copying operations, but also reduces memory usage. occupancy.
Zand Engine 2 has even more flexibility. A happy development is to allow destructor--executing a class method before the object is destroyed. This is also good for utilizing memory, allowing PHP to Know clearly when there are no references to an object and allocate the freed memory to other uses.