note 87556 deleted from function.include by peehaa

From: Date: Fri, 09 Dec 2016 22:45:33 +0000
Subject: note 87556 deleted from function.include by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208379@lists.php.net to get a copy of this message
Note Submitter: johan ---- If you wish to abstract away include calls inside functions, or programmatically juggle files to include using functions, just remember: 1. Declare any variables as global if you want those variables "included" in the global scope (ie. if they are used outside the file). 2. Functions are naturally global, so files that only contain functions (libs, sets of api's what have you) can be included anywhere. eg. <?php function nav($i){ include "nav$i.php"; } nav(1); // same as... include "nav1.php"; // ...as long as variables are global ?> So don't feel you can only include/require at the beginning of files, or outside/before functions. You can totally program any sophisticated include behavior.

« previous php.notes (#208379) next »