Home >Backend Development >PHP Tutorial >Section 2 - Object Model of PHP5 - Classes and Objects in PHP5 [2]_PHP Tutorial
Section 2 - The object model of PHP5
PHP5 has a single inheritance, restricted access, and overloadable object model. "Inheritance", which will be discussed in detail later in this chapter, includes classes parent-child relationship. In addition, PHP supports restricted access to properties and methods. You can declare members as private and not allow external classes to access them. Finally, PHP allows a subclass to overload members from its parent class.
//haohappy Note: There is no private in PHP4, only public.private is very beneficial for better implementation of 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 explicitly pass and return objects by reference. 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.
There is a more direct object model , the handle-based system has additional advantages: improved efficiency, less memory usage, and greater flexibility.
In previous versions of PHP, scripts copied objects by default. Now PHP5 only moves handles, which needs to be updated 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. More memory can be reserved for other operations, which also improves efficiency.
//haohappy Note: Based on handles, that means two objects can point to the same memory, which not only reduces the copy action, but also reduces the memory usage .
Zand Engine 2 has more flexibility. A happy development is to allow destructors - executing a class method before the object is destroyed. This is also good for utilizing memory, letting PHP know clearly what When there is no reference to the object, allocate the free memory to other uses.