<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.dir.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.dir.php',
    1 => 'dir',
    2 => 'Return an instance of the Directory class',
  ),
  'up' => 
  array (
    0 => 'ref.dir.php',
    1 => 'Directory Functions',
  ),
  'prev' => 
  array (
    0 => 'function.closedir.php',
    1 => 'closedir',
  ),
  'next' => 
  array (
    0 => 'function.getcwd.php',
    1 => 'getcwd',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/dir/functions/dir.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.dir" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">dir</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">dir</span> &mdash; <span class="dc-title">Return an instance of the Directory class</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.dir-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>dir</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$directory</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.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"><span class="type"><a href="class.directory.php" class="type Directory">Directory</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  
  <p class="para rdfs-comment">
   A pseudo-object-oriented mechanism for reading a directory.  The
   given <code class="parameter">directory</code> is opened.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.dir-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">directory</code></dt>
    <dd>
     <p class="para">
      Directory to open
     </p>
    </dd>
   
   
    <dt><code class="parameter">context</code></dt>
    <dd>
      <p class="para">A <a href="stream.contexts.php" class="link">context stream</a>
<span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>.</p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.dir-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an instance of <span class="classname"><a href="class.directory.php" class="classname">Directory</a></span>, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> in case of error.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.dir-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</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>

 </div>


 <div class="refsect1 examples" id="refsect1-function.dir-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>dir()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     Please note the fashion in which <span class="function"><a href="directory.read.php" class="function">Directory::read()</a></span>&#039;s
     return value is checked in the example below. We are explicitly
     testing whether the return value is identical to (equal to and of
     the same type as - see <a href="language.operators.comparison.php" class="link">
     Comparison Operators</a> for more information) <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> since
     otherwise, any directory entry whose name evaluates to <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> will
     stop the loop.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$d </span><span style="color: #007700">= </span><span style="color: #0000BB">dir</span><span style="color: #007700">(</span><span style="color: #DD0000">"/etc/php5"</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Handle: " </span><span style="color: #007700">. </span><span style="color: #0000BB">$d</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">handle </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"Path: " </span><span style="color: #007700">. </span><span style="color: #0000BB">$d</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">path </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />while (</span><span style="color: #0000BB">false </span><span style="color: #007700">!== (</span><span style="color: #0000BB">$entry </span><span style="color: #007700">= </span><span style="color: #0000BB">$d</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">read</span><span style="color: #007700">())) {<br />   echo </span><span style="color: #0000BB">$entry</span><span style="color: #007700">.</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">$d</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Handle: Resource id #2
Path: /etc/php5
.
..
apache
cgi
cli</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.dir-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    The order in which directory entries are returned by the read method is
    system-dependent.
   </p>
  </p></blockquote>
 </div>

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