update examples to test result of opendir() before trying to call readdir().

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@77443 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
jim winstead 2002-04-09 22:29:22 +00:00
parent 262c9bfa38
commit ba0ec0111a

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.37 $ -->
<!-- $Revision: 1.38 $ -->
<reference id="ref.dir">
<title>Directory functions</title>
<titleabbrev>Directories</titleabbrev>
@ -248,21 +248,22 @@ if ($dir = @opendir("/tmp")) {
<![CDATA[
// Note that !== did not exist until 4.0.0-RC2
<?php
$handle=opendir('/path/to/files');
echo "Directory handle: $handle\n";
echo "Files:\n";
if ($handle = opendir('/path/to/files')) {
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 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);
}
/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}
closedir($handle);
?>
]]>
</programlisting>
@ -281,13 +282,14 @@ closedir($handle);
<programlisting role="php">
<![CDATA[
<?php
$handle = opendir('.');
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($handle);
}
closedir($handle);
?>
]]>
</programlisting>