|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47534 RecursiveDirectoryIterator::current() always returns SplFileInfo
Submitted: 2009-03-01 01:12 UTC Modified: 2010-04-27 06:28 UTC
From: david at ethos-consulting dot com Assigned: colder (profile)
Status: Not a bug Package: SPL related
PHP Version: 5.2.9 OS: MacOS X 10.5.6
Private report: No CVE-ID: None
 [2009-03-01 01:12 UTC] david at ethos-consulting dot com
The return value for RecursiveDirectoryIterator::current() is _always_ SplFileInfo, which isn't as expected and is less useful than the behavior in previous versions within the 5.2.x branch. At least one other programmer has submitted this as a bug, as well (see #37530), however he was dismissed with the standard RTFM boilerplate.

This is a flaw in the behavior of the class, IMO, however, since there's no way to _disable_ the class from returning SplFileInfo. The SPL documentation briefly refers to a flag that can be passed to __construct() named "CURRENT_AS_FILEINFO", which would indicate to me that the default behavior for the class is to return something _other_ than SplFileInfo for current().

The docs seem to back that up, listing the variable behavior of current() to alternate between getFilename() and getFileInfo(). However, the class consistently returns SplFileInfo, regardless of the flags provided to the constructor.

Reproduce code:

function testReturnTypeOfCurrent ( $Directory, $assertion )
    $assertion = sprintf($assertion, '$Node');
    echo 'Asserting: ' . $assertion, "\n";

    foreach ( $Directory as $Node )
        echo ( @assert($assertion) ?
           'Assertion Passed!' : 'Assertion Failed!' ), "\n";
} // END testReturnTypeOfCurrent

   new RecursiveDirectoryIterator('/path/to/walk'),
   'gettype(%s) == "string"'

    new RecursiveDirectoryIterator(
    '%s instanceof SplFileInfo'

Expected result:
Asserting: gettype($Node) == 'string'
Assertion Passed! x number of items in /path/to/walk

Asserting: $Node instanceof SplFileInfo
Assertion Passed! x number of items in /path/to/walk

Actual result:
Asserting: gettype($Node) == 'string'
Assertion Failed! x number of items in /path/to/walk

Asserting: $Node instanceof SplFileInfo
Assertion Passed! x number of items in /path/to/walk


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-27 06:28 UTC]
-Status: Assigned +Status: Bogus
 [2010-04-27 06:28 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Possible flags that affect the current values are:


The default is CURRENT_AS_SELF, you probably want CURRENT_AS_PATHNAME.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 09:01:28 2024 UTC