|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48788 RecursiveDirectoryIterator doesn't descend into symlinked directories
Submitted: 2009-07-03 15:10 UTC Modified: 2009-07-08 03:10 UTC
From: craig dot marvelley at boxuk dot com Assigned:
Status: Closed Package: SPL related
PHP Version: 5.3.0 OS: Linux (Debian)
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: craig dot marvelley at boxuk dot com
New email:
PHP Version: OS:


 [2009-07-03 15:10 UTC] craig dot marvelley at boxuk dot com
In a Windows environment, RecursiveDirectoryIterator will treat 
symlinked directories as valid directories, descending into them 
accordingly. However on Linux this isn't the case, with a symlink being 
treated as a file (leaf). 

Reproduce code:
// create a 'proper' directory with a file
file_put_contents('new_dir/test.txt', 'test');

// create a symlink to our directory
symlink('new_dir', 'symlink_dir');

$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__));

foreach($iterator as $object) {
    echo $object->getFilename() . "\n";

Expected result:
On Windows Vista, I get this (executed in file test.php):


Which I would expect; the symlinked directory is treated as a regular 
directory, so the test file appears twice.

Actual result:
On Linux (same scenario):


The symlinked directory appears, but as a leaf; the contents of the 
directory are not discovered.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-08 03:10 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

To avoid breaking how existing code works a new constant is introduced 
for the RecursiveDirectoryIterator() that directs the code to follow 
This constant RecursiveDirectoryIterator::FOLLOW_SYMLINKS can be passed 
a flag to the constructor to trigger symlink following
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Dec 16 08:01:27 2019 UTC