torben          Sun Feb 10 13:47:29 2002 EDT

  Modified files:              
    /phpdoc/en/functions        dir.xml 
  Log:
  Clarified readdir() a bit.
  
  
Index: phpdoc/en/functions/dir.xml
diff -u phpdoc/en/functions/dir.xml:1.30 phpdoc/en/functions/dir.xml:1.31
--- phpdoc/en/functions/dir.xml:1.30    Mon Feb  4 20:04:11 2002
+++ phpdoc/en/functions/dir.xml Sun Feb 10 13:47:27 2002
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.30 $ -->
+<!-- $Revision: 1.31 $ -->
  <reference id="ref.dir">
   <title>Directory functions</title>
   <titleabbrev>Directories</titleabbrev>
@@ -209,7 +209,17 @@
      </methodsynopsis>
     <para>
      Returns the filename of the next file from the directory. The
-     filenames are not returned in any particular order.
+     filenames are returned in the order in which they are stored by
+     the filesystem.
+    </para>
+    <para>
+     Please note the fashion in which <function>readdir</function>'s
+     return value is checked in the examples below. We are explicitly
+     testing whether the return value is equal and identical to
+     &false; since otherwise, any directory entry whose name evaluates
+     to &false; will stop the loop.
+    </para>
+    <para>
      <example>
       <title>List all files in the current directory</title>
       <programlisting role="php">
@@ -219,9 +229,17 @@
 $handle=opendir('.');
 echo "Directory handle: $handle\n";
 echo "Files:\n";
+
+/* This is the correct way to loop over the directory. */
 while (false !== ($file = readdir($handle))) { 
     echo "$file\n";
 }
+
+/* This is the WRONG way to loop over the directory. */
+while ($file = readdir($handle)) { 
+    echo "$file\n";
+}
+
 closedir($handle); 
 ?>
 ]]>


Reply via email to