Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.920
diff -u -r1.920 common.inc
--- includes/common.inc	8 Jun 2009 05:00:11 -0000	1.920
+++ includes/common.inc	9 Jun 2009 09:04:08 -0000
@@ -2241,6 +2241,30 @@
 }
 
 /**
+ * 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.
+ * Use example: list($result, $output) = drupal_eval($code_str, $variables);
+ *
+ * @param $code_str
+ *   The code to evaluate.
+ * @param $variables
+ *   Variables to import to local variable scope.
+ * @return
+ *   An array containing the returned value and the printed output of the code.
+ */
+function drupal_eval($code_str, $variables = array()) {
+  extract($variables);
+  ob_start();
+  $result = eval($code_str);
+  $output = ob_get_clean();
+  return array($result, $output);
+}
+
+/**
  * Returns the path to a system item (module, theme, etc.).
  *
  * @param $type
