Search code examples
phpreturn

Is it considered "bad style" when not ending php function with `return` statement?


I want to load Google fonts in the head-section of my page using a php-function.

My <head>-area looks like this:

...
<?=Class->loadGoogleFonts($fontsfile)?>
...

Now I have the feeling, that I have to end the loadGoogleFonts function with a return-statement. But when I do this, there will be a "1" displayed (because of the <?=).

Is it bad style to avoid the return-statement?


Solution

  • Having no return is not bad style in general. Having <?= .. ?>is bad style if you don't want to display anything. Simply use <?php .. ?>.

    Having no return can be bad style if some code paths return a value, but other code paths do not.