News Feed
Sections




News Archive
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
June 26, 2006 @ 06: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.

0 comments voice your opinion now!
dynamic function method benchmark class microtime call_user_func dynamic function method benchmark class microtime call_user_func


blog comments powered by Disqus

Similar Posts

DevShed: Developing a Form Director Class

L2Admin.com: Battle of the server side scripting languages - Perl, Python & PHP

OpenSky Blog: Inheritance in PHP, or why you want to use an Interface or an Abstract class...

PHPixie: Benchmarking Autoloading vs Combining classes into a single file

Soledad Pendaes' Blog: PHP will never have a (real) Rails-like framework


Community Events





Don't see your event here?
Let us know!


refactor developer interview install framework release community opinion series code configure threedevsandamaybe podcast testing symfony2 unittest list language laravel introduction

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework