/*
+-------------------------------------------------- ----------------------------------+
| = 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 15--The Development of Zend Engine
In the last section of this chapter, Zeev discusses The object model brought by the Zend engine, specifically mentioning how it differs from the model in 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 were no ideas related to classes and objects. PHP3 is a purely process-oriented language. However, support for classes was added in the PHP3 alpha version on the evening of August 27, 1997. Adding a new feature to PHP, at that time only required There was very little discussion because there were too few people exploring PHP at that time. So from August 1997, PHP took the first step towards an object-oriented programming language.
Indeed, this is only the first step. Because in this There are very few relevant ideas in the design, and the support for objects is not strong enough. Using objects in this version is just a cool way to access arrays. Instead of using $foo["bar"], you can use something that looks more like Nice $foo->bar. The main advantage of the object-oriented approach is to store functionality through member functions or methods. Example 6.18 shows a typical code block. But it is not really much like the approach in Example 6.19 Different.
Listing 6.18 PHP 3 object-oriented programming Object-oriented programming in PHP3
{
var $value = "some value";
function PrintValue()
print $this-& gt;value;
}
}
$obj = new Example();
$obj->PrintValue();
?>
Listing 6.19 PHP 3 structural programming PHP3 Structured programming in PHP3
{
print $arr ["value"];
}
function CreateExample()
{
$arr["value"] = "some value";
$arr["PrintValue"] = "PrintValue ";
return $arr;
}
$arr = CreateExample();
//Use PHP's indirect reference
$arr["PrintValue"]($arr);
?>
Above we write two lines of code in the class, or explicitly pass the array to the function. But considering that there is no difference between these two options in PHP3, we can still just treat the object model as one." Syntactic whitewashing" to access arrays. People who wanted to use PHP for object-oriented development, especially those who wanted to use design patterns, quickly found that they hit a wall. Fortunately, at the time (PHP3 era) there was no Too many people want to use PHP for object-oriented development.
PHP4 changes this situation. The new version brings the concept of reference, which allows different identifiers in PHP to point to the same address in memory. This means you can use two or more names for the same variable, as in Example 6.20.
Listing 6.20 PHP 4 references References in PHP4
//$b points to the same place in memory as $a $b and $a point to the same address in memory
$b = & $a;
//we're changing $b, since $a is pointing to change $b, the address pointed to changes
//the same place - it changes too The address pointed to by $a also changes
$b = 7;
//prints 7 Output 7
print $a;
?>
Listing 6.21 Problems with objects in PHP 4 Problems using objects in PHP4
2 function MyFoo()
3 {
4 $this->me = &$this;
5 $this->value = 5;
6 }
7
8 function setValue($val)
9 {
10 $this->value = $val;
11 }
12
13 function getValue()
14 {
15 return $this->value;
16 }
17
18 function getValueFromMe()
19 {
20 return $this->me->value;
21 }
22 }
23
24 function CreateObject($class_type)
25 {
26 switch ($class_type) {
27 case "foo":
28 $obj = new MyFoo();
29 break;
30 case "bar":
31 $obj = new MyBar();
32 break;
33 }
34 return $obj;
35 }
36
37 $global_obj = CreateObject ("foo");
38 $global_obj->setValue(7);
39
40 print "Value is " . $global_obj->getValue() . "n";
41 print "Value is " . $global_obj->getValueFromMe() . "n";
Let's discuss it step by step. First, there is a MyFoo class. In the constructor, we give $this->me a reference and set it
We have three other member functions: a setter the value of this->value; one returns the value of this->value; the other returns the value of this->value->me. But isn't --$this the same thing? MyFoo::getValue() Isn't it the same as the value returned by MyFoo::getValueFromMe()?
First, we call CreateObject("foo"), which will return an object of type MyFoo. Then we call MyFoo::setValue(7). Finally , we call MyFoo::getValue() and MyFoo::getValueFromMe(), expecting to get a return value of 7.
Of course, if we get 7 in any case, the above example will not be the least meaningful in this book Example. So I’m sure you’ve guessed it – we don’t get two 7s.
But what result will we get, and more importantly, why?
What we will get is 7 respectively and 5. As for why --- there are three good reasons.
First, look at the constructor. When inside the constructor, we establish a reference between this and this->me. In other words, this and this ->me is the same thing. But we are inside the constructor. When the constructor ends, PHP needs to re-create the object (result of new MyFoo, line 28) and assign it to $obj. Because the object is not treated specially, it Like any other data type, assigning X to Y means that Y is a copy of X. That is, obj will be a copy of new MyFoo, which is an object that exists in the constructor. Obj->me How about it? Because it is a reference, it still points to the original object - this. Voila-obj and obj->me are no longer the same thing - changing one of them will not change the other.
That's the first reason. There are other reasons similar to the first one. Miraculously we are going to overcome the problem of instantiating objects (line 28). Once we assign the value returned by CreateObject to global_object, we still have to hit Same problem as above - global_object will become a copy of the return value, and again, global_object and global_object->me will no longer be the same. This is the second reason.
But, in fact, we can't go that far yet Far — Once CreateObject returns $obj, we will destroy the reference (line 34). This is the third reason.
So, how do we correct this? There are two options. One is to add ampersands everywhere, just Like Example 6.22 (lines 24, 28, 31, 37). 2. If you are lucky enough to use PHP5, you can forget all the above, PHP5 will automatically consider these for you. If you want to know how PHP5 If you consider these issues, continue reading.
Listing 6.22 WTMA syndrome in PHP 4 WTMA syndrome in PHP4
2 function MyFoo()
3 {
4 $this->me = &$this;
5 $this->value = 2;
6 }
7
8 function setValue($val)
9 {
10 $this->value = $val;
11 }
12
13 function getValue()
14 {
15 return $this->value;
16 }
17
18 function getValueFromMe()
19 {
20 return $this->me->value;
21 }
22 };
23
24 function &CreateObject($class_type)
25 {
26 switch ($class_type) {
27 case "foo":
28 $obj =& new MyFoo();
29 break;
30 case "bar":
31 $obj =& new MyBar();
32 break;
33 }
34 return $obj;
35 }
36
37 $global_obj =& CreateObject ("foo");
38 $global_obj->setValue(7);
39
40 print "Value is " . $global_obj->getValue() . "n";
41 print "Value is " . $global_obj->getValueFromMe() . "n";
PHP5 is the first PHP version to treat objects differently from other types of data. From a user's perspective, this proves to be very clear - in PHP5, objects are always passed by reference, while other types Data (such as integer, string, array) are all passed by value. Most notably, there is no need to use the & symbol to indicate passing objects by reference.
Object-oriented programming makes extensive use of object networks and inter-object connections. Complex relationships, these all require the use of references. In previous versions of PHP, references needed to be explicitly specified. Therefore, moving objects by reference is now the default, and objects are copied only when copying is explicitly requested, which is better than before .
How is it implemented?
Before PHP5, all values were stored in a special structure called zval (Zend Value). These values can be stored in simple values, such as numbers and strings. or complex values such as arrays and objects. When values are passed to or returned from functions, these values are copied, creating a structure with the same content at another address in memory.
In PHP5, the values are still Stored in a zval structure, except for objects. Objects exist in a structure called Object Store, and each object has a different ID. In Zval, the object itself is not stored, but the pointer to the object is stored. When copying a holder There is a zval structure of an object. For example, if we pass an object as a parameter to a function, we no longer copy any data. We just keep the same object pointer and notify the Object Store that this specific object now points to by another zval. Because The object itself is located in the Object Store, and any changes we make to it will affect all zval structures holding pointers to the object. This additional indirection makes PHP objects appear as if they are always passed by reference, using transparency and Efficient way.
Using PHP5, we can now go back to Example 6.21, remove all the ampersands, and everything will still work fine. When we hold a reference in the constructor (line 4) an & No symbols are needed.

技嘉的主板怎么设置键盘开机首先,要支持键盘开机,一定是PS2键盘!!设置步骤如下:第一步:开机按Del或者F2进入bios,到bios的Advanced(高级)模式普通主板默认进入主板的EZ(简易)模式,需要按F7切换到高级模式,ROG系列主板默认进入bios的高级模式(我们用简体中文来示范)第二步:选择到——【高级】——【高级电源管理(APM)】第三步:找到选项【由PS2键盘唤醒】第四步:这个选项默认是Disabled(关闭)的,下拉之后可以看到三种不同的设置选择,分别是按【空格键】开机、按组

1.处理器在选择电脑配置时,处理器是至关重要的组件之一。对于玩CS这样的游戏来说,处理器的性能直接影响游戏的流畅度和反应速度。推荐选择IntelCorei5或i7系列的处理器,因为它们具有强大的多核处理能力和高频率,可以轻松应对CS的高要求。2.显卡显卡是游戏性能的重要因素之一。对于射击游戏如CS而言,显卡的性能直接影响游戏画面的清晰度和流畅度。建议选择NVIDIAGeForceGTX系列或AMDRadeonRX系列的显卡,它们具备出色的图形处理能力和高帧率输出,能够提供更好的游戏体验3.内存电

广联达软件是一家专注于建筑信息化领域的软件公司,其产品被广泛应用于建筑设计、施工、运营等各个环节。由于广联达软件功能复杂、数据量大,对电脑的配置要求较高。本文将从多个方面详细阐述广联达软件的电脑配置推荐,以帮助读者选择适合的电脑配置处理器广联达软件在进行建筑设计、模拟等操作时,需要进行大量的数据计算和处理,因此对处理器的要求较高。推荐选择多核心、高主频的处理器,如英特尔i7系列或AMDRyzen系列。这些处理器具有较强的计算能力和多线程处理能力,能够更好地满足广联达软件的需求。内存内存是影响计算

主板上SPDIFOUT连接线序最近我遇到了一个问题,就是关于电线的接线顺序。我上网查了一下,有些资料说1、2、4对应的是out、+5V、接地;而另一些资料则说1、2、4对应的是out、接地、+5V。最好的办法是查看你的主板说明书,如果找不到说明书,你可以使用万用表进行测量。首先找到接地,然后就可以确定其他的接线顺序了。主板vdg怎么接线连接主板的VDG接线时,您需要将VGA连接线的一端插入显示器的VGA接口,另一端插入电脑的显卡VGA接口。请注意,不要将其插入主板的VGA接口。完成连接后,您可以

10月8日消息,美国汽车市场正在经历一场引擎盖下的变革,以前备受喜爱的六缸和八缸动力发动机正逐渐失去统治地位,而三缸发动机则崭露头角。10月8日的消息显示,美国汽车市场正在经历一场引擎盖下的变革。过去备受喜爱的六缸和八缸动力发动机正在逐渐失去统治地位,而三缸发动机则开始崭露头角在大多数人的印象中,美国人钟情于大排量车型,而"美式大V8"一直是美国车的代名词。然而,根据外媒近期公布的数据,美国汽车市场的格局正在发生巨大变化,引擎盖下的战斗正愈演愈烈。据了解,在2019年之前,美

随着科技的快速发展和信息技术在教育领域的广泛应用,Canvas作为一种全球领先的在线学习管理系统,正逐渐在中国教育界崭露头角。Canvas的出现,为中国教育教学方式的改革提供了新的可能性。本文将探讨Canvas在中国教育界的发展趋势及前景。首先,Canvas在中国教育界的发展趋势之一是深度融合。随着云计算、大数据和人工智能的快速发展,Canvas将越来越多地

实时全局光照(Real-time GI)一直是计算机图形学的圣杯。多年来,业界也提出多种方法来解决这个问题。常用的方法包通过利用某些假设来约束问题域,比如静态几何,粗糙的场景表示或者追踪粗糙探针,以及在两者之间插值照明。在虚幻引擎中,全局光照和反射系统Lumen这一技术便是由Krzysztof Narkowicz和Daniel Wright一起创立的。目标是构建一个与前人不同的方案,能够实现统一照明,以及类似烘烤一样的照明质量。近期,在SIGGRAPH 2022上,Krzysztof Narko

求推荐1155针的cpu哪个最好当前性能最高的1155针CPU是IntelCorei7-3770K。它拥有4个核心和8个线程,基础频率为3.5GHz,并支持TurboBoost2.0技术,最高可达到3.9GHz。此外,它还搭载了8MB的三级缓存,是一款非常出色的处理器LGA1155针最强的CPUIntel酷睿i73770K。LGA1155接口为二三代酷睿处理器所使用的接口类型,性能最好的为Intel酷睿i73770K,这款处理器参数如下:1.适用类型:台式机;2.CPU系列:酷睿i7;3.CPU


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
