Home >Backend Development >PHP Tutorial >Section 2 Object Model [2]_PHP Tutorial

Section 2 Object Model [2]_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 16:10:59756browse


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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314104.htmlTechArticlePHP5 has a single inheritance, restricted access, and overloadable object model. More details later in this chapter The "inheritance" discussed includes the parent-child relationship between classes. In addition, PHP supports attributes and methods...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn