Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid argument supplied() #1

Closed
adeshrd opened this issue Dec 27, 2014 · 0 comments
Closed

invalid argument supplied() #1

adeshrd opened this issue Dec 27, 2014 · 0 comments

Comments

@adeshrd
Copy link

adeshrd commented Dec 27, 2014

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:

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;
    }

}
@adeshrd adeshrd closed this as completed Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant