mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
WS Fixes
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@163486 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
298458a675
commit
c3fcc16c21
1 changed files with 15 additions and 17 deletions
|
@ -1,18 +1,18 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.1 $ -->
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<sect1 id="language.oop5.cloning">
|
||||
<title>Object cloning</title>
|
||||
|
||||
<para>
|
||||
Creating a copy of an object with fully replicated properties is not
|
||||
always the wanted behavior. A good example of the need for copy
|
||||
constructors, is if you have an object which represents a GTK window and the
|
||||
object holds the resource of this GTK window, when you create a duplicate
|
||||
you might want to create a new window with the same properties and have the
|
||||
new object hold the resource of the new window. Another example is if your
|
||||
object holds a reference to another object which it uses and when you
|
||||
replicate the parent object you want to create a new instance of this other
|
||||
object so that the replica has its own separate copy.
|
||||
Creating a copy of an object with fully replicated properties is not
|
||||
always the wanted behavior. A good example of the need for copy
|
||||
constructors, is if you have an object which represents a GTK window and the
|
||||
object holds the resource of this GTK window, when you create a duplicate
|
||||
you might want to create a new window with the same properties and have the
|
||||
new object hold the resource of the new window. Another example is if your
|
||||
object holds a reference to another object which it uses and when you
|
||||
replicate the parent object you want to create a new instance of this other
|
||||
object so that the replica has its own separate copy.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
@ -40,9 +40,9 @@ $copy_of_object = clone $object;
|
|||
object, and only override properties that need to be changed.
|
||||
</para>
|
||||
|
||||
<example>
|
||||
<title>Cloning an object</title>
|
||||
<programlisting role="php">
|
||||
<example>
|
||||
<title>Cloning an object</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
class MyCloneable {
|
||||
|
@ -72,10 +72,8 @@ print $obj_cloned->name . "\n";
|
|||
print $obj_cloned->address . "\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
|
Loading…
Reference in a new issue