|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-31 18:05 UTC] eric at ericmmartin dot com
Description:
------------
glob() with the GLOB_BRACE flag seems to have a bug. I believe that the colon (:) in a pattern in braces, is causing the problem.
I tried escaping the colon, but that did not seem to work.
Reproduce code:
---------------
<?php
$paths = '{c:/globtest/firstfolder,c:/globtest/secondfolder}';
$ext = '*.png';
print_r(get_files($paths,$ext));
$paths = 'c:/globtest/';
$ext = '{firstfolder/*.png,secondfolder/*.png}';
print_r(get_files($paths,$ext));
function get_files($paths, $ext) {
return glob($paths.$ext,GLOB_BRACE);
}
?>
Expected result:
----------------
Array
(
[0] => c:/globtest/firstfolder/arrow_down.png
[1] => c:/globtest/firstfolder/arrow_off.png
[2] => c:/globtest/firstfolder/arrow_up.png
[3] => c:/globtest/secondfolder/arrow_down.png
[4] => c:/globtest/secondfolder/arrow_off.png
[5] => c:/globtest/secondfolder/arrow_up.png
)
Array
(
[0] => c:/globtest/firstfolder/arrow_down.png
[1] => c:/globtest/firstfolder/arrow_off.png
[2] => c:/globtest/firstfolder/arrow_up.png
[3] => c:/globtest/secondfolder/arrow_down.png
[4] => c:/globtest/secondfolder/arrow_off.png
[5] => c:/globtest/secondfolder/arrow_up.png
)
Actual result:
--------------
Array
(
)
Array
(
[0] => c:/globtest/firstfolder/arrow_down.png
[1] => c:/globtest/firstfolder/arrow_off.png
[2] => c:/globtest/firstfolder/arrow_up.png
[3] => c:/globtest/secondfolder/arrow_down.png
[4] => c:/globtest/secondfolder/arrow_off.png
[5] => c:/globtest/secondfolder/arrow_up.png
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 19:00:02 2025 UTC |
I added BLOG_NOCHECK and found that I needed to update my first test (it was missing a directory seperator...but even after fixing that, it still fails. Here are the updated tests and results. Reproduce code: --------------- <?php $paths = '{c:/globtest/firstfolder/,c:/globtest/secondfolder/}'; $ext = '*.png'; print_r(get_files($paths,$ext)); $paths = 'c:/globtest/'; $ext = '{firstfolder/*.png,secondfolder/*.png}'; print_r(get_files($paths,$ext)); function get_files($paths, $ext) { return glob($paths.$ext,GLOB_BRACE+GLOB_NOCHECK); } ?> Actual result: -------------- Array ( [0] => c:/globtest/firstfolder/*.png [1] => c:/globtest/secondfolder/*.png ) Array ( [0] => c:/globtest/firstfolder/arrow_down.png [1] => c:/globtest/firstfolder/arrow_off.png [2] => c:/globtest/firstfolder/arrow_up.png [3] => c:/globtest/secondfolder/arrow_down.png [4] => c:/globtest/secondfolder/arrow_off.png [5] => c:/globtest/secondfolder/arrow_up.png ) The pattern looks correct! Even if I use 'arrow_off.png' instead of '*.png' for $ext, glob() fails. It seems like the colon breaks it, for some reason...It seems to be a problem with PHP thread-safe. With PHP-NTS that is provided from 5.2.1 and on it seems to work as expected. Apparently the thread-safety version (which is what common in windows) of glob has a problem with pattern that begins with '{'.I have confirmed that the nts version works as expected. I still believe that the issue is caused by the colon ':' in the pattern portion of the glob call. For example, the following is still problematic in the non-nts version: <?php $paths = 'c{:/globtest/firstfolder/,:/globtest/secondfolder/}'; $ext = '*.png'; print_r(get_files($paths,$ext)); $paths = 'c:/globtest/'; $ext = '{firstfolder/*.png,secondfolder/*.png}'; print_r(get_files($paths,$ext)); function get_files($paths, $ext) { return glob($paths.$ext,GLOB_BRACE); } ?> Notice, I moved the drive letter out of the pattern, so the pattern does not start with a '{'. It works as expected in the nts version.