Call to a member function on a non-object



function sidebar($sbtitle,$sbmain,$sbfooter){
global $sbtitle, $sbmain, $sbfooter;
$template->set_filenames(array(
'sidebar' => 'sidebar.tpl')
);
$template->assign_vars(array( 'SBHEADER' => $sbheader,
'SBMAIN' => $sbmain,
'SBFOOTER' => $sbfooter

));
$template->pparse('sidebar');

}

sidebar('MYTITLE','MAIN','Footer');

What am I doing wrong here? I recieve the Call to a member function
error.
My main goal is to create a little side bar that can be called with the
three variables. So that when using a template engine on the main page
I can diplay several of these "sidebar" with different contents. This
is what I am working towards on the main PHP page so that I can just
have {LASTTHUMB} AND {LASTBLOG} where ever I want in the .tpl page
$template->set_filenames(array(
'body' => 'main_body.tpl')
);
$template->assign_vars(array( 'COLOR' => $my_color,
'LASTTHUMB' => sidebar('PhotoTitle',
'Myphoto','PhotoFooter'),
'LASTBLOG' =>
sidebar('BlogTitle','Blog','Blogfooter')
));

$template->pparse('body');

.