Make a public object property visible in other places I am using a class inside a Drupal module. I inserted the class inside the html.tpl.php like this:

require_once(drupal_get_path('module','shop')."/jcart/jcart.php");


Now I can use its properties in the pages but I need it to use one of them ($jcart-&gt;subtotal) inside a block module I created like this:

function MYMODULE_block_info(){
    $blocks = array();
    $blocks['total'] = array(
        'info' =&gt; t('Total amount of the cart'),
                //'cache' =&gt; DRUPAL_NO_CACHE,
    );
    return $blocks;
}

/**
 * Implements MYMODULE_block_view().
 */
function total_block_view($block_name = '') {
    $block['title'] = t('Total');



        $total = $jcart-&gt;subtotal; 

    $block['content'] = $total;
    return $block;
}


notes:

I cannot add the class twice with require (because the $jcart) is being initialized inside the class and cannot be done twice
I need a block with so I think the variable is not visible in a Drupal block.
I would use a function to instantiate your class in a static fashion and then you have access to the same instance across your page load:

function MYMODULE_jcart_instance() {
  $jcart = &amp;drupal_static(__FUNCTION__, NULL);

  if (!$jcart) {
    module_load_include('php', 'shop', 'jcart/jcart');
    $jcart = new jCart(); // Or whatever this might be
  }

  return $jcart;
}


From then every time you need access to the jcart class instance anywhere else on the site you just call:

$jcart = MYMODULE_jcart_instance();


Just a quick note, putting in an include into html.tpl.php is not a good way to do this. The theme layer is not invoked until all other processing has been done so your include should really be in a module file. I've shown this above using the module_load_include() function.

Hope that helps

EDIT

I've just seen your previous question relating to this and you mention that the class is instantiated in the include file already. If that's the case just change your static function to this:

function MYMODULE_jcart_instance() {
  $included = &amp;drupal_static(__FUNCTION__, FALSE);

  if (!$included) {
    module_load_include('php', 'shop', 'jcart/jcart');
  }
}


and then add a call to this in hook_init() (this will be called before pretty much any of the rest of your code):

function MYMODULE_init() {
  MYMODULE_jcart_instance();
}


If $jcart is declared in global scope you'll need to add global $jcart to the functions that want to use it.