What is the scope of require_once in PHP?

Posted by TMG on Stack Overflow See other posts from Stack Overflow or by TMG
Published on 2010-04-21T00:31:38Z Indexed on 2010/04/21 0:33 UTC
Read the original article Hit count: 286

Simple question: Is the scope of require_once global?

For example:

<?PHP

require_once('baz.php');

// do some stuff
foo ($bar);

function foo($bar) {
    require_once('baz.php');
    // do different stuff
}

?>

When foo is called, does it re-parse baz.php? Or does it rely on the already required file from the main php file (analagous to calling require_once twice consecutively for the same include file)?

I saw this thread before, but it didn't quite answer the question:

http://stackoverflow.com/questions/1669707/should-require-once-some-file-php-appear-anywhere-but-the-top-of-the-file

Thanks for your help!

© Stack Overflow or respective owner

Related posts about php

Related posts about require-once