Error description

Our PHP error logs are getting filled with the following notice:

PHP Notice: Undefined index: #name in [my project name]/htdocs/profiles/acquia/modules/apachesolr/Solr_Base_Query.php on line 219.

This error happens when any of our customers visit our one of our search pages.

This is the code where the error is caused:

  protected function unset_filter(&$fields, $name, $value) {
    if (!isset($value)) {
      foreach ($fields as $pos => $values) {
        if ($values['#name'] == $name) {
          unset($fields[$pos]);
        }
      }
    }
    else {
      foreach ($fields as $pos => $values) {
        if ($values['#name'] == $name && $values['#value'] == $value) { // This is line 219.
          unset($fields[$pos]);
        }
      }
    }
  }

Below is a stack trace:

http://[my site]/worksheets/?filters=im_28_field_grade_level:19 (suspended)	
	add_filter(): /[my site]/profiles/acquia/modules/apachesolr/Solr_Base_Query.php at line 219	
	add_filter(): /[my site]/profiles/acquia/modules/apachesolr/Solr_Base_Query.php at line 191	
	apachesolr_search_nested_facet_items(): /[my site]/profiles/acquia/modules/apachesolr/apachesolr_search.module at line 1180	
	apachesolr_search_taxonomy_facet_block(): /[my site]/profiles/acquia/modules/apachesolr/apachesolr_search.module at line 1089	
	apachesolr_search_block_view(): /[my site]/profiles/acquia/modules/apachesolr/apachesolr_search.module at line 938	
	module_invoke(): /[my site]/includes/module.inc at line 793	
	_block_render_blocks(): /[my site]/modules/block/block.module at line 828	
	block_list(): /[my site]/sites/all/modules/contrib/context/plugins/context_reaction_block.inc at line 352	
	block_get_blocks_by_region(): /[my site]/sites/all/modules/contrib/context/plugins/context_reaction_block.inc at line 316	
	execute(): /[my site]/sites/all/modules/contrib/context/plugins/context_reaction_block.inc at line 222	
	context_page_build(): /[my site]/sites/all/modules/contrib/context/context.core.inc at line 248	
	drupal_render_page(): /[my site]/includes/common.inc at line 5480	
	drupal_deliver_html_page(): /[my site]/includes/common.inc at line 2536	
	drupal_deliver_page(): /[my site]/includes/common.inc at line 2431	
	menu_execute_active_handler(): /[my site]/includes/menu.inc at line 516	
	/[my site]/index.php at line 22	

And below is a snapshot of the variables received in the unset_filter() function:

$fields	Array [1]	
	im_36_field_themes	Array [5]	
		0	(string:2) 46	
		1	(string:2) 46	
		2	(string:2) 47	
		3	(string:2) 48	
		4	(string:2) 49	
$name	(string:18) im_36_field_themes	
$value	(string:2) 46	
$values	Array [5]	
	0	(string:2) 46	
	1	(string:2) 46	
	2	(string:2) 47	
	3	(string:2) 48	
	4	(string:2) 49	
$pos	(string:18) im_36_field_themes	
CommentFileSizeAuthor
#4 1296206-4.patch612 bytesnick_vh
#1 Solr_Base_Query.php_.patch807 bytesalexander allen

Comments

alexander allen’s picture

StatusFileSize
new807 bytes

I don't have a working copy of this module in Git (we're currently using SVN in my company), so I submitted an SVN patch instead. The attached patch fixed the PHP notice.

Thank you.

nick_vh’s picture

Status: Active » Needs work

After some digging this is appearently code from the 6.x branch so setting the right tags here. On first sight I only see one problem if you want to do this right :

if ($values['#name'] == $name && $values['#value'] == $value) {

Should become

if ((array_key_exists('#name', $values) && $values['#name'] == $name) && (array_key_exists('#value', $values) && $values['#value'] == $value)) {
nick_vh’s picture

Version: 7.x-1.0-beta5 » 6.x-1.x-dev
nick_vh’s picture

StatusFileSize
new612 bytes

Reworked it a bit to be readable and clear

nick_vh’s picture

Status: Needs work » Fixed

Committed, thanks!

nick_vh’s picture

Status: Fixed » Closed (fixed)
nick_vh’s picture

Issue summary: View changes

Added comment to code.