Zend Engine Development _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
The development of the Zend Engine. In the last section of this chapter, Zeev discusses the object model brought about by the Zend Engine. it is especially mentioned that it is different from the model in the previous versions of PHP. in the summer of 1997, we developed PHP3. we didn't have the last section in this Chapter. Zeev discussed the object model brought by the Zend Engine, it is mentioned that it is different from the models in the previous versions of PHP.
When we developed PHP3 in the summer of 1997, we had no plans to make PHP object-oriented. at that time, there was no idea about classes and objects. PHP3 is a purely process-oriented language. however, the class support is added to the PHP3 alpha version on the evening of 1997.8.27. A new feature was added to PHP, which was rarely discussed at the time, because there were too few people exploring PHP. since August 1997, PHP has taken the first step towards object-oriented programming language.

Indeed, this is only the first step. there are only a few related ideas in this design, and the support for objects is not strong enough. in this version, using objects is only a cool way to access arrays. instead of using $ foo ["bar"], you can use $ foo-> bar that looks more beautiful. the main advantage of object-oriented methods is to store functions through member functions or methods. in example 6.18, a typical code block is displayed. however, it is not very different from the practice in example 6.19.

Listing 6.18 PHP 3 object-oriented programming Object-Oriented programming in PHP3

Class Example
{
Var $ value = "some value ";
Function PrintValue ()
{
Print $ this-> value;
}
}
$ Obj = new Example ();
$ Obj-> PrintValue ();
?>
Structured programming in Listing 6.19 PHP 3 structural programming PHP3 PHP3

Function PrintValue ($ arr)
{
Print $ arr ["value"];
}

Function CreateExample ()
{
$ Arr ["value"] = "some value ";
$ Arr ["PrintValue"] = "PrintValue ";

Return $ arr;
}

$ Arr = CreateExample ();

// Use PHP's indirect reference
$ Arr ["PrintValue"] ($ arr );
?>
The above two lines of code are written in the class, or an array is passed to the function explicitly. however, considering that the two options in PHP3 are not different, we can still use the object model as a "syntactic whitewashing" to access the array.

People who want to use PHP for object-oriented development, especially those who want to use design patterns, will soon find them hitting the wall. fortunately, not many people in the PHP3 era wanted to use PHP for object-oriented development.

PHP4 has changed this situation. the new version introduces the reference concept, which promises that different PHP identifiers point to the same address in the memory. this means that you can use two or more names to name the same variable, as in example 6.20.

Reference in Listing 6.20 PHP 4 references PHP4

$ A = 5;

// $ B points to the same place in memory as $ a $ B and $ a point to the same address in memory
$ B = & $;

// We re changing $ B, since $ a is pointing to Change $ B, pointing to address change
// The same place-it changes too $ a points to the address also changed
$ B = 7;

// Prints 7 Output 7
Print $;

Sorry. in the summer of 1997, we developed PHP3. we didn't...

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.