If a file is included or required inside a function is it loaded if the function is not invoked? Example:
page.php
<?php
require('functions.php');
a();
?>
functions.php
<?php
function a(){
require('a.php');
}
function b(){
require('b.php');
}
function c(){
include('c.php');
}
?>
Are b.php or c.php loaded?
No they aren't loaded unless you actually call the functions b()
and c()
.
The code inside b.php
and c.php
will also be local to the functions they are included in. That is any variables they define won't be available outside of b()
or c()
respectively.
See PHP: include for more details.