language/oop5/object-comparison.xml
a9edd62d087ab1eb6292c795b7256e14ff9f1234
...
...
@@ -3,25 +3,20 @@
3
3
<sect1 xml:id="language.oop5.object-comparison" xmlns="http://docbook.org/ns/docbook">
4
4
<title>Comparing Objects</title>
5
5
<para>
6
-
In PHP 5, object comparison is more complicated than in PHP 4 and more
7
-
in accordance to what one will expect from an Object Oriented Language
8
-
(not that PHP 5 is such a language).
9
-
</para>
10
-
<para>
11
6
When using the comparison operator (<literal>==</literal>),
12
7
object variables are compared in a simple manner, namely: Two object
13
-
instances are equal if they have the same attributes and values, and are
8
+
instances are equal if they have the same attributes and values (values are compared with <literal>==</literal>), and are
14
9
instances of the same class.
15
10
</para>
16
11
<para>
17
-
On the other hand, when using the identity operator (<literal>===</literal>),
12
+
When using the identity operator (<literal>===</literal>),
18
13
object variables are identical if and only if they refer to the same
19
14
instance of the same class.
20
15
</para>
21
16
<para>
22
17
An example will clarify these rules.
23
18
<example>
24
-
<title>Example of object comparison in PHP 5</title>
19
+
<title>Example of object comparison</title>
25
20
<programlisting role="php">
26
21
<![CDATA[
27
22
<?php
...
...
@@ -46,7 +41,7 @@ class Flag
46
41
{
47
42
public $flag;
48
43

49
-
function Flag($flag = true) {
44
+
function __construct($flag = true) {
50
45
$this->flag = $flag;
51
46
}
52
47
}
...
...
@@ -55,7 +50,7 @@ class OtherFlag
55
50
{
56
51
public $flag;
57
52

58
-
function OtherFlag($flag = true) {
53
+
function __construct($flag = true) {
59
54
$this->flag = $flag;
60
55
}
61
56
}
...
...
@@ -102,11 +97,11 @@ o1 !== o2 : TRUE
102
97
</para>
103
98
<note>
104
99
<para>
105
-
Extensions can define own rules for their objects comparison.
100
+
Extensions can define own rules for their objects comparison
101
+
(<literal>==</literal>).
106
102
</para>
107
103
</note>
108
104
</sect1>
109
-
110
105
<!-- Keep this comment at the end of the file
111
106
Local variables:
112
107
mode: sgml
113
108