<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.phardata.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'phardata.copy.php',
    1 => 'PharData::copy',
    2 => 'Copy a file internal to the tar/zip archive to another new file within the same archive',
  ),
  'up' => 
  array (
    0 => 'class.phardata.php',
    1 => 'PharData',
  ),
  'prev' => 
  array (
    0 => 'phardata.converttoexecutable.php',
    1 => 'PharData::convertToExecutable',
  ),
  'next' => 
  array (
    0 => 'phardata.decompress.php',
    1 => 'PharData::decompress',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/phar/PharData/copy.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="phardata.copy" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PharData::copy</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL phar &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">PharData::copy</span> &mdash; <span class="dc-title">Copy a file internal to the tar/zip archive to another new file within the same archive</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-phardata.copy-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PharData::copy</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$from</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$to</code></span>): <span class="type"><a href="language.types.singleton.php" class="type true">true</a></span></div>


  <p class="para rdfs-comment">
   Copy a file internal to the tar/zip archive to another new file within the same archive.
   This is an object-oriented alternative to using <span class="function"><a href="function.copy.php" class="function">copy()</a></span> with
   the phar stream wrapper.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-phardata.copy-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">from</code></dt>
     <dd>
      <p class="para">
      </p>
     </dd>
    
    
     <dt><code class="parameter">to</code></dt>
     <dd>
      <p class="para">
      </p>
     </dd>
    
   </dl>
  </p>

 </div>

 <div class="refsect1 returnvalues" id="refsect1-phardata.copy-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Always returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-phardata.copy-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Throws <span class="classname"><a href="class.unexpectedvalueexception.php" class="classname">UnexpectedValueException</a></span> if the source file does not
   exist, the destination file already exists, write access is disabled, opening either
   file fails, reading the source file fails, or a <span class="classname"><a href="class.pharexception.php" class="classname">PharException</a></span>
   if writing the changes to the phar fails.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-phardata.copy-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 A <span class="function"><strong>PharData::copy()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     This example shows using <span class="function"><strong>PharData::copy()</strong></span> and the
     equivalent stream wrapper performance of the same thing.  The primary
     difference between the two approaches is error handling.  All PharData methods
     throw exceptions, whereas the stream wrapper uses <span class="function"><a href="function.trigger-error.php" class="function">trigger_error()</a></span>.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">try {<br />    </span><span style="color: #0000BB">$phar </span><span style="color: #007700">= new </span><span style="color: #0000BB">PharData</span><span style="color: #007700">(</span><span style="color: #DD0000">'myphar.tar'</span><span style="color: #007700">);<br /><br />    </span><span style="color: #0000BB">$phar</span><span style="color: #007700">[</span><span style="color: #DD0000">'a'</span><span style="color: #007700">] = </span><span style="color: #DD0000">'hi'</span><span style="color: #007700">;<br />    </span><span style="color: #0000BB">$phar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">copy</span><span style="color: #007700">(</span><span style="color: #DD0000">'a'</span><span style="color: #007700">, </span><span style="color: #DD0000">'b'</span><span style="color: #007700">);<br /><br />    echo </span><span style="color: #0000BB">$phar</span><span style="color: #007700">[</span><span style="color: #DD0000">'b'</span><span style="color: #007700">]; </span><span style="color: #FF8000">// Outputs "phar://myphar.tar/b"<br /></span><span style="color: #007700">} catch (</span><span style="color: #0000BB">Exception $e</span><span style="color: #007700">) {<br />    </span><span style="color: #FF8000">// Handle error<br /></span><span style="color: #007700">}<br /><br /></span><span style="color: #FF8000">// The stream wrapper equivalent of the above code.<br />// E_WARNING are triggered on error rather than exceptions<br /></span><span style="color: #0000BB">copy</span><span style="color: #007700">(</span><span style="color: #DD0000">'phar://myphar.tar/a'</span><span style="color: #007700">, </span><span style="color: #DD0000">'phar//myphar.tar/c'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'phar://myphar.tar/c'</span><span style="color: #007700">); </span><span style="color: #FF8000">// Outputs "hi"<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


</div><?php manual_footer($setup); ?>