Clarified readdir() a bit.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@69971 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Torben Wilson 2002-02-10 18:47:27 +00:00
parent c6e03fafe3
commit 37d2d048ac

View file

@ -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 @@ if ($dir = @opendir("/tmp")) {
</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 @@ if ($dir = @opendir("/tmp")) {
$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);
?>
]]>