Forums / Zen Cart Code Suggestions / "Undefined array key" warning in /includes/classes/cache.php

"Undefined array key" warning in /includes/classes/cache.php

Views: 46

Results 1 to 3 of 3
4 Sep 2025, 11:00 AM
#1
yesaul avatar

yesaul

New Zenner

Join Date:
Apr 2011
Location:
Espoo, Finland
Posts:
73
Plugin Contributions:
0

"Undefined array key" warning in /includes/classes/cache.php

Good day,

From time to time I get the following warning in the logs:

--> PHP Warning: Undefined array key "cache_data" in /includes/classes/cache.php on line 157

$sql = "select * from " . TABLE_DB_CACHE . " where cache_entry_name = '" . $zp_cache_name . "'";
$zp_cache_result = $db->Execute($sql);
$zp_result_array = unserialize(base64_decode($zp_cache_result->fields['cache_data']));

Should this line be simply modified to:

$zp_result_array = unserialize(base64_decode($zp_cache_result->fields['cache_data'] ?? ''));
  • or are there probably any issues in my (heavy modded) Zen-Cart copy?

Zen Cart 2.1.0
PHP Version: 8.3.24

4 Sep 2025, 12:56 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: "Undefined array key" warning in /includes/classes/cache.php

Better to change as follows (cache.php, sql_cache_read, starting at line 154):

      case 'database':
      $sql = "select * from " . TABLE_DB_CACHE . " where cache_entry_name = '" . $zp_cache_name . "'";
      $zp_cache_result = $db->Execute($sql);
[B]      if ($zp_cache_result->EOF) {
          return false;
      }[/B]
      $zp_result_array = unserialize(base64_decode($zp_cache_result->fields['cache_data']));
      return $zp_result_array;
      break;