Is it bad practice to output from within a function?
- by Nick
For example, should I be doing something like:
<?php
function output_message($message,$type='success') {
?>
<p class="<?php echo $type; ?>"><?php echo $message; ?></p>
<?php
}
output_message('There were some errors processing your request','error');
?>
or
<?php
function output_message($message,$type='success') {
ob_start();
?>
<p class="<?php echo $type; ?>"><?php echo $message; ?></p>
<?php
return ob_get_clean();
}
echo output_message('There were some errors processing your request','error');
?>
I understand they both achieve the same end result, but are there benefits doing one way over the other? Or does it not even matter?