Web lists-archives.com

Re: [PHP] Question about the difference between `glob` and `GlobIterator` behaviour




On 2016-03-23 02:28, Stéphane HULARD wrote:
Hello !

I’m currently working on the Hoa Project (http://hoa-project.net) about
a `glob` behaviour integration: https://github.com/hoaproject/File/pull/22

We found that there are some difference between the `glob` function and the
`GlobIterator` object.

1. `glob`
This function is able to scan only dirs with the GLOB_ONLYDIR constant
and is also able
to expand braces to match in a list of items with GLOB_BRACE.

Exemple with glob(‘/{a,b,c}/foo/bar’, GLOB_BRACE), it’ll search :
- /a/foo/bar
- /b/foo/bar
- /c/foo/bar

2. `GlobIterator`
This object has no options or constants to apply the same logic than
GLOB_ONLYDIR and GLOB_BRACE.
It’s possible to combine different iterators and obtain the same
result but it’s a lot more
complicated.

Exemple with new GlobIterator(‘/{a,b,c}/foo/bar’), it’ll search :
- /{a,b,c}/foo/bar

Is there some reason about the differences in these two implementations ?
I found that the braces expansion is not part of the “official” glob
pattern definition but
it’s definitively an awesome feature.

Thanks in advance for your attention.
Stéphane

Stéphane HULARD
Directeur technique & CEO
CH Studio - Collectif digital
2 rue d'Italie - 38490 Les Abrets
Phone: +33 (0)6 18 18 65 04
www.chstudio.fr


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

By no means do I pretend to have any insight to the internals of PHP, but if I were to take a guess, I would say that the functionality of the glob was initially modelled after the glob'ing ability found in most all *nix cli tools from years
past.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php