Typically, I\'ll write a function like so:
function alertClass($field,$full=false){ global $formErrors; $html = $full ? \' class=\"alert\"\' : \' alert\';
Using echo preculdes using the function to programmatically build some HTML for output later on, or for further processing.
echo
If in your case there's no downside to returning the HTML, I'd continue doing it. It adds flexibility.