|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31674 glob() returns no results for dirs with brackets in them.
Submitted: 2005-01-24 03:31 UTC Modified: 2005-01-24 11:01 UTC
From: miika dot ahonen at mbnet dot fi Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.0.3 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: miika dot ahonen at mbnet dot fi
New email:
PHP Version: OS:


 [2005-01-24 03:31 UTC] miika dot ahonen at mbnet dot fi
In an attempt to glob() directory with bracket ('[' and/or ']') in its name, I get no results at all.

Reproduce code:
$dir = "./dir[with]brackets";

if (!is_dir($dir))

for ($i = 0; $i < 3; $i++)
   file_put_contents($dir."/file.".$i, "foo".$i."\n");

var_dump( glob($dir."/*") );

Expected result:
Array containing files in the said directory.

Actual result:
Empty array.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-24 08:10 UTC]
Brackets make a character class,just as in regular expressions. Escape them with a \.
 [2005-01-24 11:01 UTC] miika dot ahonen at mbnet dot fi
I don't think that explains why first doing chdir() to such directory and doing just glob("*") fails in similar manner. The chdir() works fine in such cases and with readdir() I can get everything I want from there without any problems.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 25 17:01:30 2024 UTC