drupal_function_exists
Definition
drupal_function_exists($function)
includes/bootstrap.inc, line 1330
Description
Confirm that a function is available.
If the function is already available, this function does nothing. If the function is not available, it tries to load the file where the function lives. If the file is not available, it returns false, so that it can be used as a drop-in replacement for function_exists).
Parameters
$function The name of the function to check or load.
Return value
TRUE if the function is now available, FALSE otherwise.
Related topics
| Name | Description |
|---|---|
| Code registry | The code registry engine. |
Code
<?php
function drupal_function_exists($function) {
static $checked = array();
if (defined('MAINTENANCE_MODE')) {
return function_exists($function);
}
if (isset($checked[$function])) {
return $checked[$function];
}
$checked[$function] = FALSE;
if (function_exists($function)) {
registry_mark_code('function', $function);
$checked[$function] = TRUE;
return TRUE;
}
$file = db_result(db_query("SELECT filename FROM {registry} WHERE name = :name AND type = :type", array(':name' => $function, ':type' => 'function')));
if ($file) {
require_once($file);
$checked[$function] = function_exists($function);
if ($checked[$function]) {
registry_mark_code('function', $function);
}
}
return $checked[$function];
}
?> 