Bug #79733 [Nab]: glob doesn't work with backslashes on linux
| From: | david dot hlavati at gmail dot com | Date: | Thu, 25 Jun 2020 11:34:06 +0000 |
| Subject: | Bug #79733 [Nab]: glob doesn't work with backslashes on linux | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227653@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
User updated by: david dot hlavati at gmail dot com
Reported by: david dot hlavati at gmail dot com
Summary: glob doesn't work with backslashes on linux
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: CentOS7
PHP Version: 7.4.7
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2020-06-25 10:41:49] cmb@php.net
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 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