As a learning exercise, I'm developing my own PHP framework. I'm looking for a way to load views (kinda like CodeIgniter does it), without polluting my general scope. I came up with the following, basic, example:    $data['test'] = 'Hello world';$str = load_view($data, true);echo $str;function load_view($data, $store = false) {    extract($data);    ob_start();    include('view.php');    if($store)  return ob_get_clean();    else        ob_end_flush();}// End of fileview.php<p><?php echo $test; ?></p>I could also use load_view($data), which would output the contents of view.php immediately. Edit: I'm mostly worried about performance. As Peter pointed out, I'm aware that the function should be a class method that's seperate from the logic. 
Is this a proper way of loading views in PHP?
php