In an attempt to speed up my workflow and help the back end guys with integration (I'm a front end dev) I'm attempting to extend the file includes function by wrapping comments around each file include to output it's filename:
function include_module($path) {
echo "\n\n<!-- MODULE: ".basename($path, '.php')." -->\n";
include($path);
echo "\n<!-- /MODULE: ".basename($path, '.php')." -->\n\n";
}
include_module('form-controls.php');
However this results in the loss of access to any variables set outside the function. I know I can do:
global $var
But that will only give me access to $var (I'm aware I could do $var['var1'], etc), is there any way to do 'global all' or can anyone think of a different approach to wrap the comments?
Cheers :)
Try this:
function include_module($path) {
foreach($GLOBALS as $name => $value) global $$name;
echo "\n\n<!-- MODULE: ".basename($path, '.php')." -->\n";
include($path);
echo "\n<!-- /MODULE: ".basename($path, '.php')." -->\n\n";
}
include_module('form-controls.php');
You can use the following to access the globals.
extract($GLOBALS, EXTR_REFS);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With