Using sf_cache, whenever the cache was cleared the page was filled with the following error messages.

warning: Illegal offset type in isset or empty in /var/www/some.website/sites/all/modules/sf_cache/sf_cache.api.inc on line 385.
warning: Illegal offset type in /var/www/some.website/sites/all/modules/sf_cache/sf_cache.api.inc on line 388.
warning: Illegal offset type in /var/www/some.website/sites/all/modules/sf_cache/sf_cache.api.inc on line 394.
warning: Illegal offset type in /var/www/some.website/sites/all/modules/sf_cache/sf_cache.api.inc on line 394. (repeated 100 times)

Adding dsm($key) and dsm($file) to the lines above 385 in sf_cache/sf_cache.api.inc revealed the following.

$key
      ... (Object) stdClass
            fid (String, 3 characters ) 244
            uid (String, 1 characters ) 1
            filename (String, 20 characters ) filefield_ClVsyS.png
            filepath (String, 59 characters ) sites/some.website.org/files/node/1073/filefiel...
                +
                  sites/some.website.org/files/node/1073/filefield_ClVsyS.png
            filemime (String, 9 characters ) image/png
            filesize (String, 3 characters ) 675
            status (String, 1 characters ) 1
            timestamp (String, 10 characters ) 1271395424
            origname (String, 20 characters ) filefield_ClVsyS.png
      Called from /var/www/some.website/sites/all/modules/sf_cache/sf_cache.api.inc

$files
      ... (Array, 0 elements)
      Called from /var/www/some.website/sites/all/modules/sf_cache/sf_cache.api.inc

So sf_cache was being passed an object for $key when it was expecting an array. The attached patch addresses this problem, please review.

Comments

agileware’s picture

Status: Active » Needs review

Changing status to need review.

agileware’s picture

Title: Illegal offset type on lines 388 and 394 in sf_cache.api.inc after cache cleared » Illegal offset type on lines 388 and 394 in sf_cache.api.inc after cache cleared (patch attached)

Updating title

davidwhthomas’s picture

StatusFileSize
new6.17 KB

The problem here is that there's a namespace collision between the sf_cache_file_load function name and the hook hook_file_load defined by the filefield module in field_file_load

<?php
function field_file_load($fid, $reset = NULL) {
/*....*/
    foreach (module_implements('file_load') as $module) {
      $function = $module .'_file_load';
      $function($file);
    }
/*....*/
?>

A better solution, than above, would be to rename the function to avoid the namespace collision altogether. This will prevent further errors in the future.

The attached patch renames the function from sf_cache_file_load to sf_cache_file_db_load instead.

DT

wim leers’s picture

Project: Support File Cache » BundleCache
mr.j’s picture

The same problem happens on file deletion.

Renaming sf_cache_file_delete to sf_cache_file_db_delete fixed the problem for me.

neilnz’s picture

Here's a revised patch against Bundlecache incorporating #3 and #5