php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #42032 Return value of dir() not tested in example code
Submitted: 2007-07-18 15:19 UTC Modified: 2007-08-16 11:41 UTC
From: michael dot mauch at gmx dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2007-07-18 15:19 UTC] michael dot mauch at gmx dot de
Description:
------------
http://www.php.net/manual/en/class.dir.php has example code which does not check the return value of the dir() constructor. This causes a fatal error if the directory does not exist.

Reproduce code:
---------------
$d = dir("/not/existing"); 
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
   echo $entry."\n";
}
$d->close();

Expected result:
----------------
The value of $d should be tested in the example code, e.g.

$d = dir("/etc/php5"); 
if (!$d)
  die("cannot read directory");
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
   echo $entry."\n";
}
$d->close();

Also, the first sentence of the description for that example could be changed to something like:

"Please note the fashion in which the return value of $d->read() is checked in the example below."


Actual result:
--------------
Handle:
Path:

Fatal error: Call to a member function read() on a non-object in Command line code on line 4


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-16 11:41 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Only dir::read() return value note changed. Example is simplified code - it doesn't need to cover everything - I remain it intact.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 29 21:00:03 2025 UTC