Web lists-archives.com

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




Hello Jim, Aziz and thanks for your answer :)

So the `glob` function is “just” a linux’s glob porting with all it’s features and 
the Iterator is a more strict (regarding to RFCs) implementation of the `glob` feature…
We made some benches and did not spot a huge difference between an Iterator combination 
and a simple `glob` call.

The specific `glob` features are activated by some flags so I think it’s not a big problem
to does not have them when using only the `GlobIterator`.

Have a nice day 
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

> On 23 Mar 2016, at 23:32, Aziz Saleh <azizsaleh@xxxxxxxxx> wrote:
> 
> 
> 
> On Wed, Mar 23, 2016 at 6:12 PM, <lists@xxxxxxxxx> wrote:
> 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
> 
> 
> Jim is spot on, glob was indeed modeled after linux's glob function (as many of PHP's earlier functions like copy, rename, etc..):
> 
> http://man7.org/linux/man-pages/man3/glob.3.html
> 
> Which is why many (but not all) flags are similar in name and functionality.
> 
> The GlobIterator class on the other hand is more powerful and offers better usage imo, however it is not available except on v >= 5.3. The difference comes naturally with any improvements on any language. newer functionality doesn't always match the old, specially when the old are still usable side by side.
> 


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