I think, you want something like this (DEMO)
class test {
function __construct(){
ob_start();
}
public function create(){
$data=ob_get_clean();
echo "<div style='color:red;'>".$data."</div>";
}
}
$obj = new test();
echo 'hello';
$obj->create();