php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #5867 traversing directory is somewhat tricky
Submitted: 2000-07-31 11:46 UTC Modified: 2000-08-04 11:05 UTC
From: pasha at zend dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0 Latest CVS (31/07/2000) OS: not relevant
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: pasha at zend dot com
New email:
PHP Version: OS:

 

 [2000-07-31 11:46 UTC] pasha at zend dot com
this the classical example (from the maual) how to traverse files in the directory:

$d = opendir ('.');
while ($file = readdir($d))
{
	print ("$file\n");
}
closedir ($d);

unfortunately this is wrong. if the directory contains file named '0', the "while" condition evaluates to false and the loop stops.

the ugly workaround is to use something like

while (! is_bool ($file = readdir ($d))

but of course I would prefer to be able to use the clear former syntax. My overall impression that the notion of what is true and what is false in the current php is somewhat broken.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-31 12:08 UTC] waldschrott@php.net
You?re wrong. That is how autoconversion works.
You?ve to use
while (($file=readdir($d))!==FALSE) ...

That?s no ugly workaround and catches all cases. If it was a
bug it was "Scripting engine problem" (not "Misbehaving
function", but this documented in some places thus I?m
unsure if we can make it a "Documentation problem".
Thus closed, although it could be pointed out more clearly
(I think it is mentioned at the strpos() documentation)
 [2000-07-31 12:10 UTC] stas@php.net
It is not misbehaving function, it is wrong manual example.
Should be something like:
while (($file = readdir($d)) !== false) 

I'd also propose not to convert "0" to false, only '0'.
 [2000-07-31 12:11 UTC] waldschrott@php.net
BTW, I failed introducing a new operator that regards this
speciality in zends autoconversion, I proposed a kind of !!
to check against equality with FALSE.
Core-devs thought it is not necessary ... perhaps it?s true,
perhaps not.
 [2000-07-31 12:12 UTC] waldschrott@php.net
Transforming into "documentation problem"
 [2000-08-04 11:05 UTC] hholzgra@php.net
fixed in latest manual cvs
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Mon Jun 15 10:00:01 2026 UTC