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

PHPBuilder.com: Displaying Dynamic Progress Bars

Tnx.nl: PHP in Contrast to Perl

Dries Buytaert\'s Blog: Drupal webserver configurations compared

Lorna Mitchell: PHP 5.6 and the Splat Operator

Nick Halstead's Blog: Simple use of DIGG API for your blog


Community Events





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


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

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