So I was trying to use GlobIterator for unifying some file parameter handling. (Using the Iterator for symmetry with the also used RecursiveDirectoryIterator for other list params.)
But it has a peculiarity with filespecs for the current directory:
$dir = new GlobIterator("*.php");
That prepends / slashes to keys and FileObject entry names.
[pathName:SplFileInfo:private] => /index.php
[fileName:SplFileInfo:private] => /index.php
Which makes utilizing it as filename iterator less useful.
So GlobIterator is not merely a 1:1 glob() replacement wrapped in an Iterator as the manual suggests. (1) But why does the / get prepended anyway? (2) And which flag does disable this rewrite? FilesystemIterator::CURRENT_AS_FILEINFO was my first assumption, but didn’t help, neither ::KEY_AS_PATHNAME. Are there other flags? (terse manual and all)
As the old chinese proverb says, if you want an iterator that gives you an output similar to
glob(), then just use a frigging iterator over glob.So I just resorted to that:
That gives the expected unified filename list without
(strstr($glob,"/") ? "$glob" : "./$glob")wrapping or key/value probing within app logic.