You are here

function _token_eval in Custom Tokens 5

Same name and namespace in other branches
  1. 6 token_custom.module \_token_eval()

Evaluate a string of PHP code. (Copy from drupal_eval())

This is a wrapper around PHP's eval(). It uses output buffering to capture both returned and printed text.

Using this wrapper also ensures that the PHP code which is evaluated can not overwrite any variables in the calling code except the ones we need.

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.

1 call to _token_eval()
token_custom_token_values in ./token_custom.module
Implementation of hook_token_values()

File

./token_custom.module, line 18

Code

function _token_eval($code, $type, $object = null) {
  ${$type} = $object;
  ob_start();
  print eval($code);
  $output = ob_get_contents();
  ob_end_clean();
  return $output;
}