What are the ‘costs’ involved in calling an empty PHP function? The main purpose is for a CMS to trigger included module events at various points in its lifespan to handle things like security, access permissions, post processing, timing, http(s) and the like. Since there can be over a dozen modules called dozens of times each the total calls will reach the hundreds and potentially even the thousands at some point for each page load.
The initial module will basically look like the following code, which will be replaced by the object to handle whatever trigger event was fired and process the passed data:
function trigger ($trigger_name, $data=false)
{
return false;
}
Will this be a problem eventually and should I instead work in a system of the modules pre-registering a trigger to cut down on the amount of pointless function calls?
i found in this link :
http://phplens.com/lens/php-book/optimizing-debugging-php.php
A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. A similar method call is of course about 15 $localvar++ operations.
Update: 11 July 2004: The above test was on PHP 4.0.4, about 3 years ago. I tested this again
in PHP4.3.3 and calling a function now takes about 20 $localvar++ operations, and calling a method takes about 30 $localvar++ operations. This could be because $localvar++ runs faster now, or functions are slower.