From:             david at ethos-consulting dot com
Operating system: MacOS X 10.5.6
PHP version:      5.2.9
PHP Bug Type:     SPL related
Bug description:  RecursiveDirectoryIterator::current() always returns 
SplFileInfo

Description:
------------
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:
---------------
<?php

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

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

testReturnTypeOfCurrent(
    new RecursiveDirectoryIterator(
       '/path/to/walk'
       RecursiveDirectoryIterator::CURRENT_AS_FILE
    ),
    '%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


-- 
Edit bug report at http://bugs.php.net/?id=47534&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=47534&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=47534&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=47534&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=47534&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=47534&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=47534&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=47534&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=47534&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=47534&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=47534&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=47534&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=47534&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=47534&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=47534&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=47534&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=47534&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=47534&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=47534&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=47534&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=47534&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=47534&r=mysqlcfg

Reply via email to