Supressing "Undefined variable: variables in module_block_view()" without hiding the notice I tried to create a simple custom block inside a custom module. there is a notice that inform me about undefined variable, but the block rendered properly. I am not sure where the mistake in the code is, but any nudge in the right direction would be highly appreciated.

I know I can hide the error message by accessing admin/config/development/logging or by modules such as Disable Message, but that isn't what I desire since it essentially just hiding the problem under the rug and hiding other notices that I might be interested to look at.

mymodule.module

&lt;?php
/**
* Declare what blocks are provided by this module
* Implements hook_block_info().
*/

function mymodule_block_info() {
  $block = array();

  $block['myblock1'] = array(
    'info' =&gt; t('Block number 1'),
  );

  $block['myblock2'] = array( 
    'info' =&gt; t('Block number 2'),
  );

  return $block;
}

/**
* Define what our block is going to look like.
* Implements hook_block_view().
*/

function mymodule_block_view($delta='') {
  $block = array();

  switch ($delta) {
    case 'myblock1':
      $block['content'] = theme('myblock1', $variables);
      break;

    case 'myblock2':
      $block['content'] = theme('myblock2', $variables);
      break;
  }

  return $block;
}

/**
* Implementation of hook_theme().
*/

function mymodule_theme() {
  return array(
    'myblock1' =&gt; array(
      'variables' =&gt; array(),
      'template' =&gt; 'templates/block--myblock1',
    ),

    'myblock2' =&gt; array(
      'variables' =&gt; array(),
      'template' =&gt; 'templates/block--myblock2',
    ),
  );
}

?&gt;
The problem is with $block['content'] = theme('myblock1', $variables); and $block['content'] = theme('myblock2', $variables);: mymodule_block_view() doesn't define any $variables variable; just define it or use an array directly.

Since in mymodule_theme() you don't define any variable for your theme functions, just replace your mymodule_block_view() with the following one.

function mymodule_block_view($delta = '') {
  $block = array();

  switch ($delta) {
    case 'myblock1':
      $block['content'] = theme('myblock1', array());
      break;

    case 'myblock2':
      $block['content'] = theme('myblock2', array());
      break;
  }

  return $block;
}


To make the question more complete: Drupal doesn't define any global $variables nor do hook_block_view() implementations receive any $variables as parameter. Therefore, $variables could just be a local variables for your function. That is why you are getting that error: You are using a variable without to first declare it.  

Notice that if $variables were a global variable, you should still declare it as global $variables in your function, or use it as $GLOBALS['variables']. (Don't try it since it doesn't work because doesn't define any global variable with that name.)