<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Phar::__construct</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="Phar archive stream and classes" HREF="ref.phar.html"><LINK REL="PREVIOUS" TITLE="Phar->compressAllFilesGZ" HREF="function.phar-compressallfilesgz.html"><LINK REL="NEXT" TITLE="Phar->count" HREF="function.phar-count.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.phar-compressallfilesgz.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.phar-count.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.phar-construct" ></A >Phar::__construct</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN178872" ></A ><P > (no version information, might be only in CVS)</P >Phar::__construct -- Construct a Phar archive object</DIV ><DIV CLASS="refsect1" ><A NAME="AEN178875" ></A ><H2 >说明</H2 >void <B CLASS="methodname" >Phar::__construct</B > ( string fname [, int flags [, string alias]] )<BR ></BR ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN178889" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >fname</CODE ></DT ><DD ><P > Path to an existing Phar archive </P ></DD ><DT ><CODE CLASS="parameter" >flags</CODE ></DT ><DD ><P > flags to pass to parent class <B CLASS="classname" >RecursiveDirectoryIterator</B >. See <A HREF="http://www.php.net/~helly/php/ext/spl/classRecursiveDirectoryIterator.html#be0e1176d512c66500e5c26f248c89c4" TARGET="_top" >SPL RecursiveDirectoryIterator docs</A > </P ></DD ><DT ><CODE CLASS="parameter" >alias</CODE ></DT ><DD ><P > Alias with which this Phar archive should be referred to in calls to stream functionality. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN178910" ></A ><H2 >错误/异常</H2 ><P > Throws BadMethodCallException if called twice, UnexpectedValueException if the phar archive can't be opened. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN178913" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN178916" ></A ><P ><B >例 1. A <B CLASS="function" >Phar::__construct()</B > example</B ></P ><P > <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />try </font><font color="#007700">{<br /> </font><font color="#0000BB">$p </font><font color="#007700">= new </font><font color="#0000BB">Phar</font><font color="#007700">(</font><font color="#DD0000">'/path/to/my.phar'</font><font color="#007700">, </font><font color="#0000BB">CURRENT_AS_FILEINFO </font><font color="#007700">| </font><font color="#0000BB">KEY_AS_FILENAME</font><font color="#007700">,<br /> </font><font color="#DD0000">'my.phar'</font><font color="#007700">);<br />} </font><font color="#0000BB">catch </font><font color="#007700">(</font><font color="#0000BB">UnexpectedValueException $e</font><font color="#007700">) {<br /> die(</font><font color="#DD0000">'Could not open my.phar'</font><font color="#007700">);<br />} </font><font color="#0000BB">catch </font><font color="#007700">(</font><font color="#0000BB">BadMethodCallException $e</font><font color="#007700">) {<br /> echo </font><font color="#DD0000">'technically, this cannot happen'</font><font color="#007700">;<br />}<br /></font><font color="#FF8000">// this works now<br /></font><font color="#007700">echo </font><font color="#0000BB">file_get_contents</font><font color="#007700">(</font><font color="#DD0000">'phar://my.phar/example.txt'</font><font color="#007700">);<br /></font><font color="#FF8000">// and works as if we had typed<br /></font><font color="#007700">echo </font><font color="#0000BB">file_get_contents</font><font color="#007700">(</font><font color="#DD0000">'phar:///path/to/my.phar/example.txt'</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE > </P ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.phar-compressallfilesgz.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.phar-count.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Phar->compressAllFilesGZ</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.phar.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Phar->count</TD ></TR ></TABLE ></DIV ></BODY ></HTML >