|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79733 glob doesn't work with backslashes on linux
Submitted: 2020-06-25 10:02 UTC Modified: 2020-06-25 11:34 UTC
From: david dot hlavati at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.4.7 OS: CentOS7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: david dot hlavati at gmail dot com
New email:
PHP Version: OS:


 [2020-06-25 10:02 UTC] david dot hlavati at gmail dot com
First: it's possible that it's a normal behavior and I just don't know about it.

php 7.4.7 - maybe not version related

So I would like to get a bunch of maintenance classes and initialize them dynamically and I'm using the glob function for this as it's written in the test script section. This works on windows 10, however it returns with nothing on CentOS7. Forward slashes are fine in both cases, but maybe conventionally it should work the same on both systems - again; it's maybe a normal behavior. And - this is actually absolutely irrelevant, but - the forward slash solution doesn't work for creating the classes dynamically - unless if I replace the slashes before creating the classes.

File structure:
The targeted classes I would like to locate with the glob function are here: `common\\queue\\tasks\\maintenance\\`
The script is running from here: `common\\queue\\`

Test script:
        // maintenance classes are located here
        $path = 'common\\queue\\tasks\\maintenance\\';
        // only for testing purpose I'll store the classes here
        $classes = [];
        // this script file is in this path: `common\\queue\\whatever.php`
        foreach (glob(__DIR__ . "\\..\\..\\{$path}*.php") as $location) {
            $maintenanceClass = $path . basename($location, '.php');

            $classes[] = $maintenanceClass;
            // the line below is just an example as I would like to use this
            (new $maintenanceClass)->initTask(BaseModel::getConfig('maintenanceFrequency'));
        print_r($classes, true);

Expected result:
for example - if these files are on the desired place place:

    [0] => common\queue\tasks\maintenance\ActivatorMaintenance
    [1] => common\queue\tasks\maintenance\CartMaintenance
    [2] => common\queue\tasks\maintenance\EventLogMaintenance

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-25 10:22 UTC] bugreports2 at gmail dot com
why should it?

you don't use backlsashes in Linux
thats's why the constant DIRECTORY_SEPARATOR exists
 [2020-06-25 10:32 UTC] david dot hlavati at gmail dot com
I see. I didn't know about this. Sorry for taking your time.
 [2020-06-25 10:41 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-06-25 10:41 UTC]
Indeed, the directory separator on Linux is the slash, and on
Windows it's a backslash; however, Windows is fine with slashes as
well (almost always).

The namespace separator, however, has always to be backslash,
regardless of the OS.
 [2020-06-25 11:34 UTC] david dot hlavati at gmail dot com
Yeah, when I was done with this report, then I replaced the directory separator to / for the globe and $path and when I was processing the paths in the foreach I called the str_replace upon the way I tried before, so it works perfectly.

When I first noticed I just wanted to make sure that if it's a bug - which isn't after all - then it wont go unnoticed, cuz I know how helpful it can be, that the bugs are reported. On the other hand - it's time consuming if it isn't a bug, so sorry for that, next time I'll read more before posting something.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Aug 16 11:05:45 2022 UTC