0x00 Posted November 3, 2015 Share Posted November 3, 2015 I'm thinking of replacing all instances of include_once() and writing my own wrapper for it so I can log file usage (for application study only I believe). 1) Is there so little overhead involved that yes wrap and log them. 2) Should I write the include_once() lines in a way that I can easily replace with some regex * There are 69 includes overall according to grep and wc -l Quote Link to comment Share on other sites More sharing options...
requinix Posted November 3, 2015 Share Posted November 3, 2015 It's not negligible but if you need a wrapper for something like logging then it's probably worth it. I have my own wrappers which I use to make sure files are run in a new scope - no inherited variables and whatnot. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted November 3, 2015 Share Posted November 3, 2015 The fact that global variables are imported into the scope of the wrapper function rather than the global scope of the including script may actually break things. 0x00, if you commonly define global variables in auxiliary scripts (e. g. $database_connection in something like db.inc.php) and then expect them to be available in your main script, the wrapper won't work. You'll have to explicitly mark the global variables by using the $GLOBALS array or not import any globals at all (like requinix) or forget about the wrapper function and do the logging in the included scripts themselves Quote Link to comment Share on other sites More sharing options...
0x00 Posted November 3, 2015 Author Share Posted November 3, 2015 No, no globals, a single static class and then everything else comes as functions and classes (except views?). Another reason why I thought of doing this was so I can scan core files for non library usage of functions, as I already do for file access functions (which I wrap anyway.) ... lol I feel bad as I've just used define for 12 ints for request variable type names, but not sure in reality how many percentage of page requests parse form data, I'm sorta just guessing its enough to warrant them... Quote Link to comment Share on other sites More sharing options...
requinix Posted November 3, 2015 Share Posted November 3, 2015 The fact that global variables are imported into the scope of the wrapper function rather than the global scope of the including script may actually break things.That was addressed to me, right? I'm not sure what you mean. I'm talking about four functions that look like /** * @param string $filename * @param array $variables * @return mixed */ function include_once_clean() { if (func_num_args() > 1) { extract(func_get_arg(1)); } return include_once(func_get_arg(0)); }and include_once_clean("/path/to/file"); include_once_clean("/path/to/file", ["var" => "value"]); Another reason why I thought of doing this was so I can scan core files for non library usage of functions, as I already do for file access functions (which I wrap anyway.) ... lol I feel bad as I've just used define for 12 ints for request variable type names, but not sure in reality how many percentage of page requests parse form data, I'm sorta just guessing its enough to warrant them... What? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted November 3, 2015 Share Posted November 3, 2015 That was addressed to me, right? Nope, I just warned the OP that if the application relies on global variables being imported, the wrapper will break this mechanism (this can be fixed, of course). I use wrappers in the same way that you do, but I commonly see people use require to import database connections, configuration data and whatnot. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.