Bug #79733 [Com]: glob doesn't work with backslashes on linux

From: Date: Thu, 25 Jun 2020 10:22:33 +0000
Subject: Bug #79733 [Com]: glob doesn't work with backslashes on linux
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227649@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 Comment by: bugreports2 at gmail dot com Reported by: david dot hlavati at gmail dot com Summary: glob doesn't work with backslashes on linux Status: Open Type: Bug Package: *General Issues Operating System: CentOS7 PHP Version: 7.4.7 Block user comment: N Private report: N New Comment: why should it? you don't use backlsashes in Linux thats's why the constant DIRECTORY_SEPARATOR exists Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#227649) next »