Leeflets / leeflets

Beautifully Simple Websites
128 stars 29 forks source link

Warning: array_merge(): Argument #2 is not an array #113

Open d4fseeker opened 10 years ago

d4fseeker commented 10 years ago

In the file core/library/template.php the method glob_recursive() internally checks and bypasses PHP Bug 53460 but may still return false instead of an empty array() object. This causes other methods of the same file to fail with error codes.

I locally fixed it by applying the following before the return statement of the glob_recursive() method: if(!is_array($files)) $files = array();

almereyda commented 10 years ago

Would you be able to send a pull request?

d4fseeker commented 10 years ago

Sorry, I currently do not have GIT software at my hands =S Anyone reading this, please do provide one - this bug seems to break the software on all of the widespread PHP 5.3 webservers.

vana-dev commented 10 years ago

I have the same problem on php 5.3 and 5.4 ;/

d4fseeker commented 10 years ago

I confirm the bug present in PHP Versions 5.3.27-1, 5.4.21-1 and 5.5.5-1 as provided by DotDeb in a mod_php environment.

This seems to fix the issue (sorry still no diff or pull request). Please note that I am a webmaster and NOT website operator. I only fixed the issue in a customer's installation but did not spend enough time to analyse the cause and other potential problems in the app.

private function glob_recursive( $pattern, $flags = 0 ) { $files = glob( $pattern, $flags );

    // Need to be careful with the return value of glob()
    // There's a bug that returns false instead of empty array: https://bugs.php.net/bug.php?id=53460
    $dirs = glob( dirname( $pattern ) . '/*', GLOB_ONLYDIR|GLOB_NOSORT);
    if ( is_array( $dirs ) ) {
            foreach ( $dirs as $dir ) {
                $sub = $this->glob_recursive( $dir . '/' . basename( $pattern ), $flags );
                if(!is_array($sub)) $sub = array();
                $files = array_merge( $files, $sub );
            }
        }
    if(!is_array($files)) return array();
    return $files;
}
d4fseeker commented 10 years ago

I found a futher issue due to incorrect results of glob() on line 17 of the core/controller/store.php file, making it impossible to choose a template.

Having the runkit-extension installed I quickfixed it with the following auto_prepend_file code:

if(true) {
        runkit_function_rename("glob","pf_glob");
        function glob($pattern, $flags=0)  {
                $result = pf_glob($pattern,$flags);
                if(!$result)
                        $result = array();
                return $result;
        }
}

I would suggest using a _glob() function in the source code of Leeflets which defines such a "fixer" function wrapped around the original glob() code. I didn't test if it can be trivially replaced by a global search/replace and adding the function to the core but I guess that should work.

Windaiv commented 10 years ago

Hello I had the same problem. Version of my server PHP 5.3. I solved this problem by configuring PHP to CGI and launched Cgi-bin. More so there is no error.