Section 2 -- object model of PHP5 -- ClassesandObjectsinPHP5 [2]
Source: Internet
Author: User
Section 2 -- PHP5 object model PHP5 has a single-inherited, restricted-access, and reloaded object model. this chapter will discuss inheritance in detail later, including the parent-child relationship between classes. in addition, PHP supports restricted access to attributes and methods. you can declare that the members are private and do not allow external Class access. finally, PHP allows a subclass to reload members from its parent class. hao
Section 2-object model of PHP5
PHP5 has a single-inherited, restricted-access, and reload object model. this chapter will discuss inheritance in detail later, including the parent-child relationship between classes. in addition, PHP supports restricted access to attributes and methods. you can declare that the members are private and do not allow external Class access. finally, PHP allows a subclass to reload members from its parent class.
// Haohappy note: PHP4 does not have private, and only public. private is good for better encapsulation.
The object model of PHP5 treats an object as different from any other data type and is passed through reference. PHP does not require you to pass and return objects through reference explicitly. at the end of this chapter, we will elaborate on the handle-based object model. it is the most important new feature in PHP5.
With a more direct object model, the handle-based system has the following advantages: higher efficiency, less memory occupation, and greater flexibility.
In the first few versions of PHP, the script copies objects by default. now, PHP5 only moves the handle, which takes less time. the script execution efficiency is improved because unnecessary copying is avoided. while the object system brings complexity, it also brings the benefit of execution efficiency. at the same time, reducing replication means that less memory is occupied and more memory can be set aside for other operations, which also improves the efficiency.
// Haohappy Note: based on the handle, the two objects can point to the same memory, which reduces the copy operation and memory usage.
Zand engine 2 has greater flexibility. a happy development is to allow the destructor to execute a class method before the object is destroyed. this is also very good for the use of memory, so that PHP can clearly know when there is no object reference, and allocate the empty memory to other purposes.
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.