|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-10-18 12:22 UTC] cmb@php.net
-Package: SPL_Types
+Package: SPL related
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Jan 07 20:00:01 2026 UTC |
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