Bug #79733 [Opn->Nab]: glob doesn't work with backslashes on linux
| From: | cmb@php.net | Date: | Thu, 25 Jun 2020 10:41:49 +0000 |
| Subject: | Bug #79733 [Opn->Nab]: glob doesn't work with backslashes on linux | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227652@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79733&edit=1
ID: 79733
Updated by: cmb@php.net
Reported by: david dot hlavati at gmail dot com
Summary: glob doesn't work with backslashes on linux
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: CentOS7
PHP Version: 7.4.7
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2020-06-25 10:32:58] david dot hlavati at gmail dot com
I see. I didn't know about this. Sorry for taking your time.
------------------------------------------------------------------------
[2020-06-25 10:22:33] 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:02:51] david dot hlavati at gmail dot com
Description:
------------
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
backstory:
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:
Array
(
[0] => common\queue\tasks\maintenance\ActivatorMaintenance
[1] => common\queue\tasks\maintenance\CartMaintenance
[2] => common\queue\tasks\maintenance\EventLogMaintenance
)
Actual result:
--------------
Array
(
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79733&edit=1