<?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 => 'zh',
  ),
  'this' => 
  array (
    0 => 'phar.loadphar.php',
    1 => 'Phar::loadPhar',
    2 => 'Loads any phar archive with an alias',
  ),
  'up' => 
  array (
    0 => 'class.phar.php',
    1 => 'Phar',
  ),
  'prev' => 
  array (
    0 => 'phar.iswritable.php',
    1 => 'Phar::isWritable',
  ),
  'next' => 
  array (
    0 => 'phar.mapphar.php',
    1 => 'Phar::mapPhar',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/phar/Phar/loadPhar.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="phar.loadphar" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Phar::loadPhar</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::loadPhar</span> &mdash; <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">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>Phar::loadPhar</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$alias</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></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">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       the full or relative path to the phar archive to open
      </p>
     </dd>
    
    
     <dt><code class="parameter">alias</code></dt>
     <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 <span class="classname"><a href="class.pharexception.php" class="classname">PharException</a></span> will be thrown if
       a new alias is specified in this case.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-phar.loadphar-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>， 或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-phar.loadphar-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   <span class="classname"><a href="class.pharexception.php" class="classname">PharException</a></span> 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">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #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">&lt;?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">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-phar.loadphar-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="phar.mapphar.php" 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><?php manual_footer($setup); ?>