You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use this function in my project to retrive some files recursively.
But, I am getting the warning as given in the title.
The problem is with this line:
foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
According to PHP docs the function glob() returns empty array for no match and FALSE on error.
Then it gives a note saying
"On some systems it is impossible to distinguish between empty match and an error."
In the system I am currently working on, it is returning false when there is no match found leading to the warning.
I think you should modify the line so that it checks for the return value and then runs the loop.
For example.
if (!function_exists('glob_recursive')) {
// Does not support flag GLOB_BRACE
function glob_recursive($pattern, $flags = 0) {
$matched_files = glob($pattern, $flags);
$matched_dirs = glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT);
$dirs = $matched_dirs ? $matched_dirs : array();
$files = $matched_files ? $matched_files : array();
foreach ($dirs as $dir) {
$files = array_merge($files, glob_recursive($dir . '/' . basename($pattern), $flags));
}
return $files;
}
}
The text was updated successfully, but these errors were encountered:
Hi,
I am trying to use this function in my project to retrive some files recursively.
But, I am getting the warning as given in the title.
The problem is with this line:
According to PHP docs the function glob() returns empty array for no match and FALSE on error.
Then it gives a note saying
"On some systems it is impossible to distinguish between empty match and an error."
In the system I am currently working on, it is returning false when there is no match found leading to the warning.
I think you should modify the line so that it checks for the return value and then runs the loop.
For example.
The text was updated successfully, but these errors were encountered: