php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75188 RecursiveIteratorIterator::SELF_FIRST not working
Submitted: 2017-09-11 13:07 UTC Modified: 2018-10-18 12:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: candeliere at trendengineering dot it Assigned:
Status: Open Package: SPL related
PHP Version: 7.1.9 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
45 + 15 = ?
Subscribe to this entry?

 
 [2017-09-11 13:07 UTC] candeliere at trendengineering dot it
Description:
------------
According to the (hard to find) documentation, SELF_FIRST should output "branches" first, then "leaves" (in case of RecursiveDirectoryIterator, it should output folders first, then files) but it is not doing that. Apparently it returns the folder structure as the underlying filesystem is returning it untouched.
NOTE: Please understand that I'm not talking about *alphabetical* order. This is related to the fact that the test script below will generate an error ("no such file or directory)
Actually the first iteration will try to copy /<my/custom/path>/themes/SimpleSoloEmailVideo/content.php, but /<my/custom/path>/themes/SimpleSoloEmailVideo/ doesn't exist yet.
The test code would work perfectly if the SELF_FIRST order is guaranteed.
 

Test script:
---------------
    function copy_recursive($source, $dest)
    {
        if (is_dir($source)) {
            $iterator = new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
                RecursiveIteratorIterator::SELF_FIRST
            );
            foreach ($iterator as $file) {
                if ($file->isDir()) {
                    mkdir($dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName(), 0777, true);
                } else {
                    copy($file, $dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName());
                }
                error_log($file); 
            }
        } else {
            copy($source, $dest);
        }
    }


Expected result:
----------------
/<my/custom/path>/themes/SimpleSoloEmailVideo/css/
/<my/custom/path>/themes/SimpleSoloEmailVideo/css/style.css
/<my/custom/path>/themes/SimpleSoloEmailVideo/js/
/<my/custom/path>/themes/SimpleSoloEmailVideo/js/mycoolscript.js
/<my/custom/path>/themes/SimpleSoloEmailVideo/_imgs/
/<my/custom/path>/themes/SimpleSoloEmailVideo/content.php
/<my/custom/path>/themes/SimpleSoloEmailVideo/snapshot.png
/<my/custom/path>/themes/SimpleSoloEmailVideo/_hotarea_sample.php
/<my/custom/path>/themes/SimpleSoloEmailVideo/theme.xml
/<my/custom/path>/themes/SimpleSoloEmailVideo/thumb-65x65.png


Actual result:
--------------
/<my/custom/path>/themes/SimpleSoloEmailVideo/content.php
/<my/custom/path>/themes/SimpleSoloEmailVideo/snapshot.png
/<my/custom/path>/themes/SimpleSoloEmailVideo/css
/<my/custom/path>/themes/SimpleSoloEmailVideo/css/style.css
/<my/custom/path>/themes/SimpleSoloEmailVideo/js
/<my/custom/path>/themes/SimpleSoloEmailVideo/js/mycoolscript.js
/<my/custom/path>/themes/SimpleSoloEmailVideo/_hotarea_sample.php
/<my/custom/path>/themes/SimpleSoloEmailVideo/theme.xml
/<my/custom/path>/themes/SimpleSoloEmailVideo/_imgs
/<my/custom/path>/themes/SimpleSoloEmailVideo/thumb-65x65.png


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-18 12:22 UTC] cmb@php.net
-Package: SPL_Types +Package: SPL related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 17:01:30 2024 UTC