Which is faster to check, Drupal's module_exists or PHP's function_exists?
Which is faster (better performance) - module_exists or function_exists?
Based on the fact that module_exists -
http://api.drupal.org/api/function/module_exists/5
- calls a Drupal function http://api.drupal.org/api/function/module_list/5 - that could even call a database query,
AND a PHP function -
http://php.net/array_key_exists
- we're going to go with function_exists.
But with the static caching perhaps this is worth taking the trouble of benchmarking?
But function_exists also protects us (in terms of total site breakage) against api changes.
<?php
if (function_exists('bio_for_user')) {
$nid = bio_for_user($uid);
$node = node_load($nid);
// more stuff here
}
?>
Aside: I wonder if bio.module's bio_for_user function should be statically cached. I think it should.
Further aside: the "more stuff here" part got pretty interesting, in terms of how do we load a node into the theming layer ourselves (that is, when none of the ways Drupal provides are available).
Comments
Post new comment