<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.phar.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'phar.offsetset.php',
    1 => 'Phar::offsetSet',
    2 => 'Set the contents of an internal file to those of an external file',
  ),
  'up' => 
  array (
    0 => 'class.phar.php',
    1 => 'Phar',
  ),
  'prev' => 
  array (
    0 => 'phar.offsetget.php',
    1 => 'Phar::offsetGet',
  ),
  'next' => 
  array (
    0 => 'phar.offsetunset.php',
    1 => 'Phar::offsetUnset',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/phar/Phar/offsetSet.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="phar.offsetset" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Phar::offsetSet</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL phar &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Phar::offsetSet</span> &mdash; <span class="dc-title">Set the contents of an internal file to those of an external file</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-phar.offsetset-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Phar::offsetSet</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$localName</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">This
method requires the <var class="filename">php.ini</var> setting <code class="literal">phar.readonly</code> to be
set to <code class="literal">0</code> in order to work for <span class="classname"><a href="class.phar.php" class="classname">Phar</a></span>
objects.  Otherwise, a <span class="classname"><a href="class.pharexception.php" class="classname">PharException</a></span> will be thrown.</p></p></blockquote>


  <p class="para">
   This is an implementation of the <span class="interfacename"><a href="class.arrayaccess.php" class="interfacename">ArrayAccess</a></span> interface allowing
   direct manipulation of the contents of a Phar archive using
   array access brackets.  offsetSet is used for modifying an
   existing file, or adding a new file to a Phar archive.
  </p>

 </div>

 <div class="refsect1 parameters" id="refsect1-phar.offsetset-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">localName</code></dt>
     <dd>
      <p class="para">
       The filename (relative path) to modify in a Phar.
      </p>
     </dd>
    
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       Content of the file.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-phar.offsetset-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   No return values.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-phar.offsetset-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   if <a href="phar.configuration.php#ini.phar.readonly" class="link">phar.readonly</a> is <code class="literal">1</code>,
   <span class="classname"><a href="class.badmethodcallexception.php" class="classname">BadMethodCallException</a></span> is thrown, as modifying a Phar
   is only allowed when phar.readonly is set to <code class="literal">0</code>. Throws
   <span class="classname"><a href="class.pharexception.php" class="classname">PharException</a></span> if there are any problems flushing
   changes made to the Phar archive to disk.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-phar.offsetset-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 A <span class="function"><strong>Phar::offsetSet()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     offsetSet should not be accessed directly, but instead used
     via array access with the <code class="literal">[]</code> operator.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$p </span><span style="color: #007700">= new </span><span style="color: #0000BB">Phar</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/to/my.phar'</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #DD0000">'my.phar'</span><span style="color: #007700">);<br />try {<br />    </span><span style="color: #FF8000">// calls offsetSet<br />    </span><span style="color: #0000BB">$p</span><span style="color: #007700">[</span><span style="color: #DD0000">'file.txt'</span><span style="color: #007700">] = </span><span style="color: #DD0000">'Hi there'</span><span style="color: #007700">;<br />} catch (</span><span style="color: #0000BB">Exception $e</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">'Could not modify file.txt:'</span><span style="color: #007700">, </span><span style="color: #0000BB">$e</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-phar.offsetset-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
 <span class="simpara">
  <span class="function"><a href="phar.addfile.php" class="function">Phar::addFile()</a></span>, <span class="function"><a href="phar.addfromstring.php" class="function">Phar::addFromString()</a></span> and <span class="function"><strong>Phar::offsetSet()</strong></span>
  save a new phar archive each time they are called. If performance is a concern,
  <span class="function"><a href="phar.buildfromdirectory.php" class="function">Phar::buildFromDirectory()</a></span> or <span class="function"><a href="phar.buildfromiterator.php" class="function">Phar::buildFromIterator()</a></span>
  should be used instead.
 </span>
</p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-phar.offsetset-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="phar.offsetexists.php" class="function" rel="rdfs-seeAlso">Phar::offsetExists()</a> - Determines whether a file exists in the phar</span></li>
    <li><span class="function"><a href="phar.offsetget.php" class="function" rel="rdfs-seeAlso">Phar::offsetGet()</a> - Gets a PharFileInfo object for a specific file</span></li>
    <li><span class="function"><a href="phar.offsetunset.php" class="function" rel="rdfs-seeAlso">Phar::offsetUnset()</a> - Remove a file from a phar</span></li>
   </ul>
  </p>
 </div>



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