php – Glob pattern does not match anything-ThrowExceptions

Exception or error:

NOTE: The pattern in question has been removed from the PHP documentation since this thread was created.

According to the PHP documentation, the pattern ... matches all subdirectories recursively, but when I try using it, no files are matched.

According to the documentation, glob hasn’t changed since PHP 5.1, but if it matters, I am using PHP 7.2.24 .

Directory structure:

├── bar
│   └── bar_file
└── foo
    ├── 1
    │   └── foo_1_file
    └── foo_file


var_dump(glob('./.../*')); // prints array(0) {}
var_dump(glob('./.../foo_file')); // prints array(0) {}

I know there is a workaround for this problem, but I would like to know if there is a PHP native solution or if there isn’t, why the PHP reference documentation is defective.

How to solve:

The documentation is incomplete or even incorrect. As of Nov 2019, there is no code to explicitly support recursive glob syntax in PHP and the underlying operating system libraries are unlikely to support it either.

  1. There is no recursive glob syntax in IEEE 1003.1

  2. PHP UNIX implementation delegates to GLOB(3) from a standard C library. On Linux this will most likely be glibc which has no support for recursive syntax.

  3. PHP Windows implementation has no support for directory recursion

  4. None of the glob tests in PHP test suite include a test that covers a triple dot (…) syntax.

  5. According to the commit message of the change that introduced glob pattern syntax to PHP documentation, the list of special characters was based on the ones supported by djgpp libc library. The djgpp manpage states that the triple dot syntax is a nod to an old VMS feature.

    … Matches all the subdirectories, recursively (VMS aficionados, rejoice!).

All of this is strong evidence that the recursive syntax listed in the documentation will not work unless PHP is running on a platform that has support for it, e.g. DJGPP on DOS or old Windows.

Leave a Reply

Your email address will not be published. Required fields are marked *