php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #64139 Misleading warning in documentation of readdir
Submitted: 2013-02-04 11:09 UTC Modified: 2013-03-02 14:29 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: jens at bremmekamp dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Debian Squeeze, Ubuntu 12.10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jens at bremmekamp dot com
New email:
PHP Version: OS:

 

 [2013-02-04 11:09 UTC] jens at bremmekamp dot com
Description:
------------
---
From manual page: http://www.php.net/function.readdir
---

The documentation on readdir's return values is wrong for PHP >= 5.3.

The warning correctly states that on failure readdir() may return boolean false or other values equivalent to boolean false.

It then suggests to use type safe operators to check readdir's return values. The examples given follow this advice.

In PHP >= 5.3 this makes no sense.

If the return value of a function is not always boolean false, but just falsy, a type safe comparison will not give you any clue if the function failed or not.

Witnessed in both 5.3.3-7+squeeze14 and 5.4.6-1ubuntu1.1.

PLEASE NOTE:

This is not a request to change readdir's return value behaviour. This is a DOCUMENTATION BUG for this specific function's documentation.

Test script:
---------------
<?php

$handle = opendir('/non_existent_dir');
$filename = readdir($handle);              // readdir() returns NULL instead of false

if(false !== $filename) {
    unlink($filename);    // fails, because $filename is null instead of false
}

?>

Expected result:
----------------
No warning for the unlink call.

Actual result:
--------------
PHP Warning:  unlink(): No such file or directory in php shell code on line 2

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-02 14:29 UTC] salathe@php.net
-Status: Open +Status: Not a bug
 [2013-03-02 14:29 UTC] salathe@php.net
The readdir() function is expecting a resource to be passed as its argument. Your 
example passes FALSE, and as with almost all functions it will return NULL when 
called with incorrect arguments.

This is already noted under "Internal (built-in) functions" [1]. The 
documentation team has decided against adding such a warning/note to every single 
function in the manual (that follows the return-NULL-on-invalid-argument 
convention).

[1] http://www.php.net/manual/en/functions.internal.php
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 18:00:02 2026 UTC