language/oop5/cloning.xml
28529d3539b850e870e3aa97570f4db0e53daa03
...
...
@@ -16,10 +16,9 @@
16
16
</para>
17
17

18
18
<para>
19
-
An object copy is created by using the <emphasis>clone</emphasis> keyword (which calls the
20
-
object's <link linkend="object.clone">__clone()</link> method if possible).
21
-
An object's <link linkend="object.clone">__clone()</link> method
22
-
cannot be called directly.
19
+
An object copy is created by using the <literal>clone</literal> keyword
20
+
(which calls the object's <link linkend="object.clone">__clone()</link>
21
+
method if possible).
23
22
</para>
24
23

25
24
<informalexample>
...
...
@@ -31,7 +30,7 @@ $copy_of_object = clone $object;
31
30
</informalexample>
32
31

33
32
<para>
34
-
When an object is cloned, PHP 5 will perform a shallow copy of all of the
33
+
When an object is cloned, PHP will perform a shallow copy of all of the
35
34
object's properties. Any properties that are references to other variables
36
35
will remain references.
37
36
</para>
...
...
@@ -87,10 +86,10 @@ $obj->object2 = new SubObject();
87
86
$obj2 = clone $obj;
88
87

89
88

90
-
print("Original Object:\n");
89
+
print "Original Object:\n";
91
90
print_r($obj);
92
91

93
-
print("Cloned Object:\n");
92
+
print "Cloned Object:\n";
94
93
print_r($obj2);
95
94

96
95
?>
...
...
@@ -133,6 +132,28 @@ MyCloneable Object
133
132

134
133
</example>
135
134

135
+
<para>
136
+
It is possible to access a member of a freshly cloned
137
+
object in a single expression:
138
+
</para>
139
+
<example>
140
+
<title>Access member of freshly cloned object</title>
141
+
<programlisting role="php">
142
+
<![CDATA[
143
+
<?php
144
+
$dateTime = new DateTime();
145
+
echo (clone $dateTime)->format('Y');
146
+
?>
147
+
]]>
148
+
</programlisting>
149
+
&example.outputs.similar;
150
+
<screen>
151
+
<![CDATA[
152
+
2016
153
+
]]>
154
+
</screen>
155
+
</example>
156
+

136
157
</sect1>
137
158
138
159
<!-- Keep this comment at the end of the file
139
160