I load a page within my template system, the page looks like this When i load the page, i use ob_get_contents, like this: ob_start(); require $file; $inc = ob_get_contents(); ob_end_clean(); return array( 'header_menu'=>$usemenufile, 'header_js'=>$javascripts, 'header_css'=>$stylesheets, 'header_template'=>$usetemplate, 'header_class'=>$classes, 'header_function'=>$functions, 'page_content'=>$inc ); Now, when i output the page, everything works, but it dont load the classes/function untill the end. So i cant use them.. i output like this (this is the short version, without checking the file etc.. $lh = $template->load_page("somepage.php"); foreach($lh['header_class'] as $a) { require($a); } then i print the page print $template->showpage($lg['page_content']);