You are here

function drupal_eval in Drupal 4

Same name and namespace in other branches
  1. 5 includes/common.inc \drupal_eval()
  2. 6 includes/common.inc \drupal_eval()

Evaluate a string of PHP code.

This is a wrapper around PHP's eval(). It uses output buffering to capture both returned and printed text. Unlike eval(), we require code to be surrounded by <?php ?> tags; in other words, we evaluate the code as if it were a stand-alone PHP file.

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.

Parameters

$code: The code to evaluate.

Return value

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

Related topics

2 calls to drupal_eval()
block_list in modules/block.module
Return all blocks in the specified region for the current user.
filter_filter in modules/filter.module
Implementation of hook_filter(). Contains a basic set of essential filters.

File

includes/common.inc, line 1196
Common functions that many Drupal modules will need to reference.

Code

function drupal_eval($code) {
  ob_start();
  print eval('?>' . $code);
  $output = ob_get_contents();
  ob_end_clean();
  return $output;
}