Is doing something like
_________________________
//index.php
...
require("header.php");
...
_________________________
_________________________
//header.php
printHeader()
function printHeader(){
echo 'something';
...
}
_________________________
considered a bad practice to avoid?
I personally believe that the execution of a require()
(or require_once()
or include()
, that's not the point) call should only add a "link" to other functions/objects and never execute anything on its own. In other words in my opinion a require should behave in a very similar way to the import/using of other oo languages.
The example that I've written above is pretty trivial but obviously I'm writing also against every kind of "side effects". The define function or some tricks with sessions are other abuses that I have found often in some included files.