<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.splfileinfo.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'splfileinfo.openfile.php',
    1 => 'SplFileInfo::openFile',
    2 => 'Gets an SplFileObject object for the file',
  ),
  'up' => 
  array (
    0 => 'class.splfileinfo.php',
    1 => 'SplFileInfo',
  ),
  'prev' => 
  array (
    0 => 'splfileinfo.iswritable.php',
    1 => 'SplFileInfo::isWritable',
  ),
  'next' => 
  array (
    0 => 'splfileinfo.setfileclass.php',
    1 => 'SplFileInfo::setFileClass',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/spl/splfileinfo/openfile.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="splfileinfo.openfile" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SplFileInfo::openFile</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.2, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SplFileInfo::openFile</span> &mdash; <span class="dc-title">Gets an SplFileObject object for the file</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-splfileinfo.openfile-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SplFileInfo::openFile</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$mode</code><span class="initializer"> = &quot;r&quot;</span></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$useIncludePath</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></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.resource.php" class="type resource">resource</a></span></span> <code class="parameter">$context</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="class.splfileobject.php" class="type SplFileObject">SplFileObject</a></span></div>

  <p class="para rdfs-comment">
   Creates an <span class="classname"><a href="class.splfileobject.php" class="classname">SplFileObject</a></span> <span class="type"><a href="language.types.object.php" class="type object">object</a></span> of
   the file. This is useful because <span class="classname"><a href="class.splfileobject.php" class="classname">SplFileObject</a></span>
   contains additional methods for manipulating the file whereas
   <span class="classname"><a href="class.splfileinfo.php" class="classname">SplFileInfo</a></span> is only useful for gaining information,
   like whether the file is writable.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-splfileinfo.openfile-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">mode</code></dt>
     <dd>
      <p class="para">
       The mode for opening the file. See the <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span>
       documentation for descriptions of possible modes. The default 
       is read only.
      </p>
     </dd>
    
    
     <dt><code class="parameter">useIncludePath</code></dt>
     <dd>
      <p class="para">
       值设为 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> 时，也会在
<a href="ini.core.php#ini.include-path" class="link">include_path</a> 中搜索文件名。
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para">
       <code class="literal">上下文（context）</code>的说明请参考手册中的 <a href="context.php" class="link">上下文（context）</a>章节。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-splfileinfo.openfile-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The opened file as an <span class="classname"><a href="class.splfileobject.php" class="classname">SplFileObject</a></span> <span class="type"><a href="language.types.object.php" class="type object">object</a></span>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-splfileinfo.openfile-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   A <span class="classname"><a href="class.runtimeexception.php" class="classname">RuntimeException</a></span> if the file cannot be
   opened (e.g. insufficient access rights).
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-splfileinfo.openfile-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        <code class="parameter">context</code> is now nullable.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-splfileinfo.openfile-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="methodname"><strong>SplFileInfo::openFile()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fileinfo </span><span style="color: #007700">= new </span><span style="color: #0000BB">SplFileInfo</span><span style="color: #007700">(</span><span style="color: #DD0000">'/tmp/foo.txt'</span><span style="color: #007700">);<br /><br />if (</span><span style="color: #0000BB">$fileinfo</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isWritable</span><span style="color: #007700">()) {<br /><br />    </span><span style="color: #0000BB">$fileobj </span><span style="color: #007700">= </span><span style="color: #0000BB">$fileinfo</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">openFile</span><span style="color: #007700">(</span><span style="color: #DD0000">'a'</span><span style="color: #007700">);<br /><br />    </span><span style="color: #0000BB">$fileobj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #DD0000">"appended this sample text"</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-splfileinfo.openfile-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="classname"><a href="class.splfileobject.php" class="classname">SplFileObject</a></span></li>
    <li><span class="function"><a href="function.stream-context-create.php" class="function" rel="rdfs-seeAlso">stream_context_create()</a> - 创建资源流上下文</span></li>
    <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - 打开文件或者 URL</span></li>
   </ul>
  </p>
 </div>


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