<!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>Loads any phar archive with an alias</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="phar.iswritable.html">Phar::isWritable</a></div> <div class="next" style="text-align: right; float: right;"><a href="phar.mapphar.html">Phar::mapPhar</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.loadphar" class="refentry"> <div class="refnamediv"> <h1 class="refname">Phar::loadPhar</h1> <p class="verinfo">(PHP >= 5.3.0, PECL phar >= 1.0.0)</p><p class="refpurpose"><span class="refname">Phar::loadPhar</span> — <span class="dc-title">Loads any phar archive with an alias</span></p> </div> <div class="refsect1 description" id="refsect1-phar.loadphar-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">final</span> <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">bool</span> <span class="methodname"><strong>Phar::loadPhar</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$alias</code></span> ] )</div> <p class="para rdfs-comment"> This can be used to read the contents of an external Phar archive. This is most useful for assigning an alias to a phar so that subsequent references to the phar can use the shorter alias, or for loading Phar archives that only contain data and are not intended for execution/inclusion in PHP scripts. </p> </div> <div class="refsect1 parameters" id="refsect1-phar.loadphar-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">filename</code></em></span> <dd> <p class="para"> the full or relative path to the phar archive to open </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">alias</code></em></span> <dd> <p class="para"> The alias that may be used to refer to the phar archive. Note that many phar archives specify an explicit alias inside the phar archive, and a <a href="class.pharexception.html" class="classname">PharException</a> will be thrown if a new alias is specified in this case. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-phar.loadphar-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 errors" id="refsect1-phar.loadphar-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> <a href="class.pharexception.html" class="classname">PharException</a> is thrown if an alias is passed in and the phar archive already has an explicit alias </p> </div> <div class="refsect1 examples" id="refsect1-phar.loadphar-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-687"> <p><strong>Example #1 A <span class="function"><strong>Phar::loadPhar()</strong></span> example</strong></p> <div class="example-contents"><p> Phar::loadPhar can be used anywhere to load an external Phar archive, whereas Phar::mapPhar should be used in a loader stub for a Phar. </p></div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">try {<br /> </span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">loadPhar</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/to/phar.phar'</span><span style="color: #007700">, </span><span style="color: #DD0000">'my.phar'</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://my.phar/file.txt'</span><span style="color: #007700">);<br />} catch (</span><span style="color: #0000BB">PharException $e</span><span style="color: #007700">) {<br /> echo </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.loadphar-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="phar.mapphar.html" class="function" rel="rdfs-seeAlso">Phar::mapPhar()</a> - Reads the currently executed file (a phar) and registers its manifest</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.iswritable.html">Phar::isWritable</a></div> <div class="next" style="text-align: right; float: right;"><a href="phar.mapphar.html">Phar::mapPhar</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>