Section 2 - Object Model of PHP5_PHP Tutorial

WBOY
Release: 2016-07-21 16:00:55
Original
817 people have browsed it

/*
+-------------------------------------------------- ----------------------------------+
| = This article is read by Haohappy<>
| = Notes from the Chapter Classes and Objects
| = Translation + personal experience
| = To avoid possible unnecessary trouble, please do not reprint, thank you
| = We welcome criticisms and corrections, and hope to make progress together with all PHP enthusiasts!
| = PHP5 Research Center: http://blog.csdn.net/haohappy2004
+---------- -------------------------------------------------- ------------------+
*/

Section 2--PHP5 object model

PHP5 has a single A heavy-inherited, restricted-access, overloadable object model. "Inheritance," discussed in detail later in this chapter, involves parent-child relationships between classes. In addition, PHP supports restricted access to properties and methods. You can Declare members as private and do 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 for more information There are benefits to implementing encapsulation well.

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, It 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 Because unnecessary copying is avoided, while the object system brings complexity, it also brings benefits in execution efficiency. At the same time, reducing copying means that less memory is occupied, and more memory can be left for other operations. This 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. A happy development is to allow destruction - executing a class method before the object is destroyed. This is also good for utilizing memory, letting PHP clearly know when there is no object left. Reference, allocate the free memory to other uses.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316960.htmlTechArticle/* +--------------------- -------------------------------------------------- --------+ |=This article is Haohappy's notes from the chapter ClassesandObjects when reading CorePHP Programming |=Translation is mainly + personal...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!