/*
+------------------------------------------------ ----------------------------------+
| = This article is read by Haohappy<
| = Notes from the Chapter Classes and Objects
| = Translation + personal experience
| = To avoid unnecessary trouble that may occur, please do not reprint, thank you
| = Criticisms and corrections are welcome, and I hope that all PHP enthusiasts Make progress together!
| = PHP5 Research Center: http://blog.csdn.net/haohappy2004
+-------------------------- -------------------------------------------------- ---+
*/
Section 2--PHP5's object model
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 good 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.
With 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 takes less time. Script execution efficiency The improvement 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, leaving more memory for other applications. Operation, which also improves efficiency.
//haohappy Note: Based on handles, it means that two objects can point to the same memory, which not only reduces copy actions but also reduces memory usage.
Zand Engine 2 has greater flexibility performance. A welcome development is to allow destructors - executing a class method before the object is destroyed. This is also good for memory utilization, allowing PHP to clearly know when there are no references to the object and allocate the vacated memory to other uses.
The above introduces the second section of p5 - the object model of PHP5, including the content of p5. I hope it will be helpful to friends who are interested in PHP tutorials.