Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Community Crosstalk:
Matthew O'Phinney & Scott Johnson on Dynamic Function/Method Calls
Jun 26, 2006 @ 11:14:51

In two related posts from Scott Johnson and Matthew Weir O'Phinney, there's a question about metaprogramming in PHP, specifically between the use of call_user_func, call_user_func_array, and variable function calls (as asked by Scott).

One of the characteristics of meta programming is lots and lots of dynamicism everywhere. So here's my php question: Is there a real difference between call_user_func versus call_user_func_array and the variable function syntax i.e. $function_name() ? As best as a quick experiment shows they seem to function the same although I did a quick hack / quick doc check as opposed to really drilling into it. Any efficiency benefits in doing it one way or another?

Matthew replies on his blog by running some benchmarks (and wondering why Scott didn't run his own).

Back to benchmarking. Scott asks, "Is there a real difference between call_user_func versus call_user_func_array and the variable function syntax i.e. $function_name()?"

The short answer: absolutely. The long answer? Read on.

He details what the differences are in the functionality (how they're used and all) as well as examples of their usage. He whips up a test class and function to go through different benchmarks, testing response times with the microtime functionality of PHP. He results aren't too surprising, but you'll have to check out his post to get the full details.

tagged: dynamic function method benchmark class microtime call_user_func dynamic function method benchmark class microtime call_user_func

Link:

Community Crosstalk:
Matthew O'Phinney & Scott Johnson on Dynamic Function/Method Calls
Jun 26, 2006 @ 11:14:51

In two related posts from Scott Johnson and Matthew Weir O'Phinney, there's a question about metaprogramming in PHP, specifically between the use of call_user_func, call_user_func_array, and variable function calls (as asked by Scott).

One of the characteristics of meta programming is lots and lots of dynamicism everywhere. So here's my php question: Is there a real difference between call_user_func versus call_user_func_array and the variable function syntax i.e. $function_name() ? As best as a quick experiment shows they seem to function the same although I did a quick hack / quick doc check as opposed to really drilling into it. Any efficiency benefits in doing it one way or another?

Matthew replies on his blog by running some benchmarks (and wondering why Scott didn't run his own).

Back to benchmarking. Scott asks, "Is there a real difference between call_user_func versus call_user_func_array and the variable function syntax i.e. $function_name()?"

The short answer: absolutely. The long answer? Read on.

He details what the differences are in the functionality (how they're used and all) as well as examples of their usage. He whips up a test class and function to go through different benchmarks, testing response times with the microtime functionality of PHP. He results aren't too surprising, but you'll have to check out his post to get the full details.

tagged: dynamic function method benchmark class microtime call_user_func dynamic function method benchmark class microtime call_user_func

Link:


Trending Topics: