Download & Extend

Undefined index errors = PHP E' Notices!

Project:Fusion
Version:6.x-1.1
Component:Code
Category:bug report
Priority:major
Assigned:Unassigned
Status:needs review

Issue Summary

It may be appropriate to roll this in with the other issue as they are likely somewhat related. There are a number of places where I get undefined index or undefined variable errors from the fusion_core or subthemes. For example in template.php line 69 uses $vars['sidebar_first'] but it's possible that there is no sidebar_first set so it throws an error.

It's easy to work around these with isset() or defining all the possible indexes in the template.php file.

This is slightly different from base theme which is arguably designed never to be unset in fusion_core since it's not designed to be used as the actual theme so I've opened it as a separate issue but if merging them is preferred that's great too.

Comments

#1

I can replicate this -

Undefined index: width in fusion_core_preprocess_block() (line 271 of /sites/all/themes/fusion/fusion_core/template.php).

Undefined index: total in fusion_core_preprocess_block() (line 256 of /sites/all/themes/fusion/fusion_core/template.php).

#2

Status:active» postponed (maintainer needs more info)

I don't know how to replicate this, I don't just see these errors on my install. Can either of you elaborate on your setup with fusion_core and subtheme and what you did with with blocks/sidebar and what pages you saw these errors on?

#3

Version:6.x-1.x-dev» 6.x-1.1

The error
Undefined index: header_center in fusion_core_preprocess_block() (line 293 of .../sites/all/themes/sitekit/fusion_core/template.php)
occurs when a child theme define their new regions.

It seems that function fusion_core_set_regions creates a list of regions, not including new regions in the child theme.

#4

@jbrauer, nirbhasa - Fusion requires that the sidebar regions exist. You don't have to use them (assign blocks to them), but they are used in grid calculations and need to stay in your info file.

@azovsky - Children themes can definitely provide additional regions; that's something we do all the time. I've spent quite a bit of time trying to reproduce this, but I haven't had any luck. And I can't logically figure out what conditions might cause it to occur. fusion_core_set_regions() does return a static array of regions, but if additional regions are defined in the theme and a block is assigned to one of them, it gets added to the $regions var through this line in fusion_core_preprocess_block():

<?php
  $regions
[$vars['block']->region]['count']++;
?>

Just curious - which version of PHP are you running? Is there any version of PHP where that line would cause problems, I wonder? i.e., a version where ++ would not return 1 on a null key

#5

Status:postponed (maintainer needs more info)» closed (cannot reproduce)

#6

Title:Undefined index errors» Undefined index errors = PHP E' Notices!
Priority:normal» major
Status:closed (cannot reproduce)» active

The problem does exist.

Here is mine;

from Pressflow 6.22 with PHP 5.3.8

Notice: Undefined index: width in fusion_core_preprocess_block() (line 309 of /var/www/virtual/peterbowey.com.au/sites/all/themes/fusion/fusion_core/template.php).

Notice: Undefined index: total in fusion_core_preprocess_block() (line 294 of /var/www/virtual/peterbowey.com.au/sites/all/themes/fusion/fusion_core/template.php).

Notice: Undefined index: count in fusion_core_preprocess_block() (line 292 of /var/www/virtual/peterbowey.com.au/sites/all/themes/fusion/fusion_core/template.php).

I am used to correcting PHP E-Notices with Pressflow+PHP5.3x,
I will see what I can do here.... :-)

#7

Current Solution / Code Patch:

fusion/fusion_core/template.php
(+ indicates changes)

<?php
/**
* Block preprocessing
*/
function fusion_core_preprocess_block(&$vars) {
  global
$theme_info, $user;
  static
$regions, $sidebar_first_width, $sidebar_last_width, $grid_name, $grid_width, $grid_fixed;

 
// Initialize position to avoid notice if function returns.
 
$vars['position'] = '';

 
// Do not process blocks outside defined regions
 
if (!in_array($vars['block']->region, array_keys($theme_info->info['regions']))) {
    return;
  }

 
// Initialize block region grid info once per page
 
if (!isset($regions)) {
   
$grid_name = substr(theme_get_setting('theme_grid'), 0, 7);
   
$grid_width = (int)substr($grid_name, 4, 2);
   
$grid_fixed = (substr(theme_get_setting('theme_grid'), 7) != 'fluid') ? 1 : 0;
   
$sidebar_first_width = (fusion_core_block_list('sidebar_first')) ? theme_get_setting('sidebar_first_width') : 0;
   
$sidebar_last_width = (fusion_core_block_list('sidebar_last')) ? theme_get_setting('sidebar_last_width') : 0;
   
$regions = fusion_core_set_regions($grid_width, $sidebar_first_width, $sidebar_last_width);
  }

// Added: just return if empty ['count']
+  if (empty($regions[$vars['block']->region]['count'])) {
+    return;
+  }

 
// Increment block count for current block's region, add first/last position class
 
$regions[$vars['block']->region]['count']++;
 
$region_count = $regions[$vars['block']->region]['count'];
 
$total_blocks = $regions[$vars['block']->region]['total'];
 
$vars['position'] = ($region_count == 1) ? 'first' : '';
 
$vars['position'] .= ($region_count == $total_blocks) ? ' last' : '';
  ..
  ..
?>

#8

Status:active» needs review
nobody click here