What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.



dir — A pseudo-object-oriented wrapper for many of the directory functions.


mixed dir(dir);
string dir: Directory pathname


Resource pointer on success; FALSE for other cases


dir() is a pseudo-object-oriented wrapper for all the directory functions that work with directory streams. It is certainly one of PHP's oddball functions - an early experiment in implementing object-oriented features for PHP. (See the notes for an anecdote from Jim Winstead, the author of the function.)

When the function is called, it opens a directory stream to directory dir and returns an object. When the directory stream is opened, a resource pointer for the stream is created. This pointer is stored as a class property called handle and the pathname of the directory is stored as a class property called path . In addition to these properties, the object contains three methods called read() , rewind() , and close() . These methods are wrappers for the readdir() , rewinddir() , and closedir() functions, and behave in a similar fashion. The methods require no arguments and are called using the following syntax:

$object_name->method_name ();

The function returns FALSE if the open_basedir configuration directive is set and directory dir is not below the directory specified in open_basedir. The function also returns FALSE if a directory stream for directory dir could not be opened.


The following quote from Jim Winstead, author of the dir function, discusses how the function came to be:

“"The object-oriented interface was just an experiment to see if it could be done. At the time, the object-oriented features of PHP were new, and there was nothing else that implemented an object-oriented PHP interface at the C level. Apparently I intended to write a object-oriented interface to gd at one point. (See I'm not sure why that never happened."”


If dir() fails because a directory stream could not be opened to the directory, a warning is generated. To suppress the warning, place a single @ before the function call:

$dir_object = @ dir ('directory_path');


From versions 3.0 and 4.0


Example 244. List all directories in the current working directory

// For PHP3, use: $directory = '.';
$directory = getcwd ();

$dir_object = @ dir ($directory)
    or die ("Could not open a directory stream for <i>$directory</i>");

// Display information about the directory stream
// print_r() was introduced in PHP 4
print_r ($dir_object);

while ($entry = $dir_object->read ()) {
       print "<br />$entry";
$dir_object->close ();

PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at The authors of this book have elected not to choose any options under the OPL. This online book was obtained from and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.