<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>set the contents of an internal file to those of an external file</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="phar.offsetget.html">Phar::offsetGet</a></div> <div class="next" style="text-align: right; float: right;"><a href="phar.offsetunset.html">Phar::offsetUnset</a></div> <div class="up"><a href="class.phar.html">Phar</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="phar.offsetset" class="refentry"> <div class="refnamediv"> <h1 class="refname">Phar::offsetSet</h1> <p class="verinfo">(PHP >= 5.3.0, PECL phar >= 1.0.0)</p><p class="refpurpose"><span class="refname">Phar::offsetSet</span> — <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="type"><span class="type void">void</span></span> <span class="methodname"><strong>Phar::offsetSet</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$offset</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$value</code></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 <em>phar.readonly</em> to be set to <em>0</em> in order to work for <a href="class.phar.html" class="classname">Phar</a> objects. Otherwise, a <a href="class.pharexception.html" class="classname">PharException</a> will be thrown.</p></p></blockquote> <p class="para"> This is an implementation of the <span class="interfacename"><a href="class.arrayaccess.html" 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> <span class="term"><em><code class="parameter">offset</code></em></span> <dd> <p class="para"> The filename (relative path) to modify in a Phar. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">value</code></em></span> <dd> <p class="para"> Content of the file. </p> </dd> </dt> </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.html#ini.phar.readonly" class="link">phar.readonly</a> is <em>1</em>, <a href="class.badmethodcallexception.html" class="classname">BadMethodCallException</a> is thrown, as modifying a Phar is only allowed when phar.readonly is set to <em>0</em>. Throws <a href="class.pharexception.html" class="classname">PharException</a> 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-693"> <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 <em>[]</em> operator. </p></div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?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">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-phar.offsetset-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="phar.offsetexists.html" class="function" rel="rdfs-seeAlso">Phar::offsetExists()</a> - determines whether a file exists in the phar</span></li> <li class="member"> <span class="function"><a href="phar.offsetget.html" class="function" rel="rdfs-seeAlso">Phar::offsetGet()</a> - Gets a PharFileInfo object for a specific file</span></li> <li class="member"> <span class="function"><a href="phar.offsetunset.html" class="function" rel="rdfs-seeAlso">Phar::offsetUnset()</a> - remove a file from a phar</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="phar.offsetget.html">Phar::offsetGet</a></div> <div class="next" style="text-align: right; float: right;"><a href="phar.offsetunset.html">Phar::offsetUnset</a></div> <div class="up"><a href="class.phar.html">Phar</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>