svn: /phpdoc/kr/trunk/language/oop5/ cloning.xml

From: Date: Mon, 06 Oct 2014 15:59:40 +0000
Subject: svn: /phpdoc/kr/trunk/language/oop5/ cloning.xml
Groups: php.doc.kr 
Request: Send a blank email to doc-kr+get-1927@lists.php.net to get a copy of this message
acidd15 Mon, 06 Oct 2014 15:59:40 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=335017 Log: initial translate Changed paths: A phpdoc/kr/trunk/language/oop5/cloning.xml Added: phpdoc/kr/trunk/language/oop5/cloning.xml =================================================================== --- phpdoc/kr/trunk/language/oop5/cloning.xml (rev 0) +++ phpdoc/kr/trunk/language/oop5/cloning.xml 2014-10-06 15:59:40 UTC (rev 335017) @@ -0,0 +1,151 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- $Revision$ --> +<!-- EN-Revision: 331135 Maintainer: acidd15 Status: ready --> +<!-- Reviewed: no --> + + <sect1 xml:id="language.oop5.cloning" xmlns="http://docbook.org/ns/docbook"> + <title>객체 복제</title> + + <para> + 객체를 복사할때 프로퍼티까지 전부 복제하는것이 어떤경우에는 기대하는 동작이 아닐수 있습니다. + 복사 생성자가 필요한 좋은 예를 들어보면, GTK 윈도를 나타내는 객체가 있고, 그 객체가 GTK 윈도의 리소스를 가지고 있는경우 복사를 할때 + 동일한 프로퍼티를 가지는 윈도우를 만들고 새 객체가 새 윈도우의 리소스를 보유하도록 하고 싶을수도 있습니다. + 다른 예로 객체가 다른 객체의 참조를 가질경우, 부모 객체를 복제 할때 복제본이 독립적일수 있도록 해당 객체의 인스턴스를 새롭게 만들고 싶은 경우가 있습니다. + </para> + + <para> + 객체의 복사는 <emphasis>clone</emphasis> 키워드를 사용해서 할 수 있습니다(이 키워드는 객체의 <link linkend="object.clone">__clone()</link> 가 존재하는경우 해당 메서드를 호출합니다.) + 객체의 <link linkend="object.clone">__clone()</link> 메서는 직접 호출 할 수 없습니다. + </para> + + <informalexample> + <programlisting> +<![CDATA[ +$copy_of_object = clone $object; +]]> + </programlisting> + </informalexample> + + <para> + 객체가 복제할때, PHP 5 는 객체의 프로퍼티들에 대해서 얕은 복사를 행합니다. + 어떤 프로퍼티이든 다른 변수에대한 참조이며, 또한 참조로 유지 됩니다. + </para> + + <methodsynopsis xml:id="object.clone"> + <type>void</type><methodname>__clone</methodname> + <void/> + </methodsynopsis> + + <para> + 복제가 완료된후, <link linkend="object.clone">__clone()</link> 메서드가 정의되어 있으면, 새로 생성된 오브젝트의 <link linkend="object.clone">__clone()</link> + 메서드가 호출될것이며, 이때 필요할 경우 프로퍼티에 대한 변경을 행할 수 있습니다. + </para> + + <example> + <title>Cloning an object</title> + <programlisting role="php"> +<![CDATA[ +<?php +class SubObject +{ + static $instances = 0; + public $instance; + + public function __construct() { + $this->instance = ++self::$instances; + } + + public function __clone() { + $this->instance = ++self::$instances; + } +} + +class MyCloneable +{ + public $object1; + public $object2; + + function __clone() + { + // Force a copy of this->object, otherwise + // it will point to same object. + $this->object1 = clone $this->object1; + } +} + +$obj = new MyCloneable(); + +$obj->object1 = new SubObject(); +$obj->object2 = new SubObject(); + +$obj2 = clone $obj; + + +print("Original Object:\n"); +print_r($obj); + +print("Cloned Object:\n"); +print_r($obj2); + +?> +]]> + </programlisting> + &example.outputs; + <screen role="php"> +<![CDATA[ +Original Object: +MyCloneable Object +( + [object1] => SubObject Object + ( + [instance] => 1 + ) + + [object2] => SubObject Object + ( + [instance] => 2 + ) + +) +Cloned Object: +MyCloneable Object +( + [object1] => SubObject Object + ( + [instance] => 3 + ) + + [object2] => SubObject Object + ( + [instance] => 2 + ) + +) +]]> + + </screen> + + </example> + + </sect1> + +<!-- Keep this comment at the end of the file +Local variables: +mode: sgml +sgml-omittag:t +sgml-shorttag:t +sgml-minimize-attributes:nil +sgml-always-quote-attributes:t +sgml-indent-step:1 +sgml-indent-data:t +indent-tabs-mode:nil +sgml-parent-document:nil +sgml-default-dtd-file:"~/.phpdoc/manual.ced" +sgml-exposed-tags:nil +sgml-local-catalogs:nil +sgml-local-ecat-files:nil +End: +vim600: syn=xml fen fdm=syntax fdl=2 si +vim: et tw=78 syn=sgml +vi: ts=1 sw=1 +--> Property changes on: phpdoc/kr/trunk/language/oop5/cloning.xml ___________________________________________________________________ Added: svn:eol-style + native Added: svn:keywords + Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL

« previous php.doc.kr (#1927) next »