ZF-9506: Zend/Cache/Backend/File.php: Error on cache clean with hashed_directory_level > 0 when at least one subdir is empty



if ((is_dir($file)) and ($this->_options['hashed_directory_level']>0)) {
     // Recursive call
     $result = array_unique(array_merge($result, $this->_get($file . DIRECTORY_SEPARATOR, $mode, $tags)));

If the directory $file is empty then this:

line 741

if ($glob === false) {
     return true;

will return true and

line 808

return array_unique($result);

will turn it to false (true or false does not matter) - problem is that this is NOT an array.

So next "array_merge()" will start a cascade of errors for each recursive call.

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /var/www/libraries/ZendFramework-1.10.0-minimal/library/Zend/Cache/Backend/File.php on line 805

Maybe there is a better solution, but this seems to work fine for me:

line 803

if ((is_dir($file)) and ($this->_options['hashed_directory_level']>0)) {
    // Recursive call
    $tmp_result = $this->_get($file . DIRECTORY_SEPARATOR, $mode, $tags);
    if (is_array($tmp_result)) {
        $result = array_unique(array_merge($result, $tmp_result));

Best regards, Anton

Anton Stöckl


just a code styling change to understand this issue

I did some small changes in trunk on r21636.

The failure isn't on clean - it's on get*. I don't know how I can write a test for it because the failure only generates if glob returns false. Normally glob retuns an empty array but a note on says: {quote} On some systems it is impossible to distinguish between empty match and an error. {quote}

Can you please test it.

You are right, it's on _get! Triggered by "clean" which sometimes makes one directory empty.

I have copied you changed File.php and will test tomorrow as I can't do today.

Cheers, Anton

Just tested your changes -> works fine for me! :-)

Cheers, Anton

fixed in r21636 (trunk) and r21642 (1.10 branch)

Thanks for testing Anton.