Problem/Motivation

Unchecked assumptions about cache/cache variables causes warning/notice mess.

Cache usage inside module's main code assumes in many points some variables as objects/array even though it happens frequently they're not.

Hence we have broken property access like in this code

 $cache = cache_get($type);
  // If nothing is set in the cache then recreate it.
  if (!isset($cache->cid)) {
    _ccl_update_cache();
    $cache = cache_get($type);
  }
  return $cache->data; // often here $cache is just "false"

or incorrect use of array functions (foreach, array_keys) on non-array or straight-up non-set variables, like here:

  if (in_array($node->type, array_keys($node_cache['ct']))) { // $node_cache['ct'] is often not set/not an array
      foreach ($node_cache['ct'][$node->type] as $id => $link) {
        if ($processed_link = _ccl_prepare_link($link, $dest, $node)) {
          $element['#links']['ccl-ct-' . $id] = $processed_link;
        }
      }
    }

Proposed resolution

Simple `isset` or `is_array` checks will remove the problem.
(small patch attached, but the fix is trivial).

Comments

giuspe created an issue. See original summary.

  • bkoether committed 68f943c on 7.x-1.x authored by giuspe
    Issue #3076543 by giuspe: unchecked object/array access causes multiple...
bkoether’s picture

Assigned: Unassigned » bkoether
Status: Active » Fixed

Thanks @giuspe,

I applied your patch and pushed it into the next release.

Ben

bkoether’s picture

Status: Fixed » Closed (fixed)