Jump to content

Function Overheads


0x00

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.