PHP object-oriented history

Source: Internet
Author: User
Tags sleep function traits
The first perl script of PHP is PHP/FI of C language, PHP/FI2.0 and PHP3.0, and ZendEngine is introduced to PHP4 to make PHP more powerful, introduce ZendEngine2 in PHP5 and rewrite PHP's object-oriented model so that PHP can not only develop quickly, but also implement more complex architectures and even meet the needs of enterprise applications.

The first perl script of PHP, to PHP/FI of C language, to PHP/FI 2.0 and PHP3.0, until PHP4, Zend Engine is introduced to make PHP more powerful, introduce the new Zend Engine2 in PHP5 and rewrite the PHP object-oriented model so that PHP can not only develop quickly, but also implement more complex architectures and even meet the needs of enterprise applications.

PHP didn't have object-oriented at the beginning. it wasn't until PHP4 had some object-oriented shadows that PHP5 had actually implemented the object-oriented model. PHP object-oriented history includes two phases:

PHP4-Zend Engine stage

At this time, there is no real object-oriented, because PHP does not implement the three main features of object-oriented, all member methods and member functions are public, and member variables are declared through var.

At this time, the constructor and class name are the same. During sequence and deserialization, the magic functions _ sleep and _ wakeup can be called. Well, this is called a magic function rather than a magic method, because it is originally an independent function. When serialization is executed, PHP will determine the type of the current variable. if it is IS_OBJECT, the _ sleep function is automatically called.

After 4.0.2, you can use parent: To call the method of the parent class. The parent here is only a special process for function calls.

In the PHP kernel implementation, classes and functions share an opcode (ZEND_DECLARE_FUNCTION_OR_CLASS), which is distinguished by the extended_value field. the storage of classes and functions is separated.

In general, PHP4's object-oriented architecture is a bit of scaffolding, and there are some object-oriented forms after various customization.

PHP5-Zend Engine2 stage

5.0.0 introduces Zend Engine2, so far PHP has actually introduced the object-oriented mechanism.
Zend Engine2 overrides the PHP object-oriented model, including the definition of the builder and the destructor, added object-oriented features such as private member variables, static member variables, interfaces, and heavy loads, and added magic methods. In addition to the object-oriented feature, Zend Engine2 introduces the exception handling control flow. See specific: http://www.zend.com/engine2/ZendEngine-2.0.pdf

5.1.0 added :__ isset and _ unset methods.

5.3.0 added: _ invoke method, static binding later, definition of constants and attributes of heredoc and nowdoc supported classes, and _ callStatic method.

5.4.0 adds Traits. Trait is similar to a class, but it aims to combine functions in a fine-grained and consistent manner. Trait cannot be instantiated. It adds a combination of horizontal features for traditional inheritance; that is, members of the application class do not need to inherit.

In general, PHP5 has implemented the object-oriented model and can implement enterprise-level applications based on PHP5. However, some new functions and features are not used much in the actual development process, such as Traits and namespace. In many cases, the business determines the technology, and the demand determines the implementation.

However, this article only serves as an example for you to understand your PHP object-oriented thinking.
A little rusty.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.