finder_eval

Versions
6--1
finder_eval($code, $variables = array())

Evaluate a string of PHP code.

This is a wrapper around PHP's eval(). It uses output buffering to capture both returned value and printed text. Allows to use variables with the given code. Using this wrapper also ensures that the PHP code which is evaluated can not overwrite any variables in the calling code, unlike a regular eval() call. In other words, we evaluate the code with independent variable scope.

Parameters

$code The code to evaluate.

$variables Variables to import to local variable scope.

Return value

A string containing the printed output of the code, followed by the returned output of the code.

▾ 3 functions call finder_eval()

finder_optionwidgets_finder_element in modules/finder_optionwidgets/finder_optionwidgets.module
Implementation of hook_finder_element().
finder_results in ./finder.module
Create finder results output.
finder_views_get_args in modules/finder_views/finder_views.module
Convert finder arguments text field entry to an array of arguments.

Code

./finder.module, line 1605

<?php
function finder_eval($code, $variables = array()) {
  global $theme_path, $theme_info, $conf;

  // Store current theme path.
  $old_theme_path = $theme_path;

  // Restore theme_path to the theme, as long as drupal_eval() executes,
  // so code evaluted will not see the caller module as the current theme.
  // If theme info is not initialized get the path from theme_default.
  if (!isset($theme_info)) {
    $theme_path = drupal_get_path('theme', $conf['theme_default']);
  }
  else {
    $theme_path = dirname($theme_info->filename);
  }

  extract($variables);

  ob_start();
  print eval('?>'. $code);
  $output = ob_get_contents();
  ob_end_clean();

  // Recover original theme path.
  $theme_path = $old_theme_path;

  return $output;
}
?>

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.