Is the following example appropriate for PHP\'s require_once construct?
function foo( $param )
{
require_once \"my_file.php\" ;
//
// do somethin
This is something of a religious debate.
require
and include
statements at the top of the file:dependencies are clearly documented in a consistent reliable place.
increased readability/maintainability
OP code caching is simpler (although you could argue that this doesn't affect the developer directly)
require
and include
statements at the top of the file:If you're doing some kind of dynamic runtime including (such as with __autoload()), a hardcoded statement at the top of the file is impossible.
If only one execution path in the code uses an include, having it included every time, unconditionally is a waste of resources.
long list of include
or require
statement is just noise the developer must scroll past when editing a file. Of course, a long list of dependencies can be viewed as a sign that the code should be broken up into smaller more focused pieces, so maybe you could spin this one as a PRO because it makes a code smell stand out.