Is it bad practice to output from within a function?
        Posted  
        
            by 
                Nick
            
        on Programmers
        
        See other posts from Programmers
        
            or by Nick
        
        
        
        Published on 2012-09-13T09:35:05Z
        Indexed on 
            2012/09/13
            9:50 UTC
        
        
        Read the original article
        Hit count: 359
        
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?
© Programmers or respective owner