Development of the Zend engine based on PHP5.0 object model
Source: Internet
Author: User
In the last part of this series of articles, the author discusses the object model brought about by the Zend Engine, especially the differences between it and the models in the previous versions of PHP. In the summer of 1997, PHP3 was announced that it was not intended to make PHP object-oriented in the last part of this series. The author discussed the object model brought by the Zend Engine, it is particularly mentioned that it is different from the models in the previous versions of PHP.
In the summer of 1997, PHP3 announced that it was not intended 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 was added to the PHP3 alpha version on the evening of 1997.8.27. adding a new feature to PHP requires a very small amount of discussion at that time, because there were too few people exploring PHP at that time. since August 1997, PHP has taken the first step towards object-oriented programming language.
Indeed, this is only the first step. because there are only a few coherent ideas in this design, the support for objects is not strong enough. in this version, the application object is only a cool method for accessing arrays. instead of applying $ foo ["bar"], you can apply the $ foo-> bar that looks more beautiful. an important advantage of object-oriented methods is that they store their functions through member functions or methods. example 1 shows a typical code block. however, it is not quite different from the practice in example 6.19.
Listing1 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 Listing2 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 treat the object model as a "syntactic whitewashing" to visit the array.
People who want to use PHP for object-oriented development, especially those who want to apply the design pattern, soon invented them. fortunately, at that time (in the PHP3 era), not many people 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 apply two or more names to name the same variable, as in Example 3.
Reference in Listing3 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 transformation
// The same place-it changes too $ a points to the address also changes
$ B = 7;
// Prints 7 Output 7
Print $;
?>
Since building an object network pointing to each other is the basis of all object-oriented design patterns, this improvement is of great significance. when the reference promises to build more powerful object-oriented exploitation programs, PHP's similar approach to viewing objects and other types of data brings great pain to developers. as any PHP4 programmer will tell you, exploitation of programs will suffer from WTMA (Way Too Many Ampersands &) syndrome. if you want to build a practical application, you will feel extremely bitter. look at example 3 and you will understand.
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