cvs: phpdoc /en/functions dir.xml

From: Date: Tue, 09 Apr 2002 22:29:24 +0000
Subject: cvs: phpdoc /en/functions dir.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969344238@lists.php.net to get a copy of this message
jimw Tue Apr 9 18:29:24 2002 EDT Modified files: /phpdoc/en/functions dir.xml Log: update examples to test result of opendir() before trying to call readdir(). Index: phpdoc/en/functions/dir.xml diff -u phpdoc/en/functions/dir.xml:1.37 phpdoc/en/functions/dir.xml:1.38 --- phpdoc/en/functions/dir.xml:1.37 Sat Apr 6 14:25:31 2002 +++ phpdoc/en/functions/dir.xml Tue Apr 9 18:29:22 2002 @@ -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 @@ <![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 WRONG way to loop over the directory. */ + while ($file = readdir($handle)) { + echo "$file\n"; + } -/* This is the correct way to loop over the directory. */ -while (false !== ($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 @@ <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>

« previous php.doc (#969344238) next »