While working on a way to allow translatable variables in Drupal I found that drupal_eval is directly using $conf instead of calling variable_get:

function drupal_eval($code) {
  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 evaluated 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);
  }

  ob_start();
  print eval('..breaks format..' . $code);
  $output = ob_get_contents();
  ob_end_clean();

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

  return $output;
}

I can't see any obvious reason for it - and any direct access to $conf makes future changes to $conf / variable_get / etc harder to do - wrappers provide most value if ALL access is done via those wrapper.

The attached patch changes this.

CommentFileSizeAuthor
core.drupalEval.patch1 KBAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

drupal_was_my_past’s picture

While drupal_eval was renamed php_eval in 7.x, it's still calling a global $conf. Though I'm not sure if the issue of whether this is bad form or not is true, I can verify the issue.

drupal_was_my_past’s picture

Version: 7.x-dev » 8.x-dev
Component: base system » php.module

Changing to 8.x.

jameswoods’s picture

Status: Needs work » Needs review

I was going to work on this issue in 8.x, but the php_eval function in ore/modules/php/php.module doesn't seem to use global $conf anymore. It uses config('system.theme')->get('default').

I'm going to update the status to "needs review".

-James

swentel’s picture

Version: 8.x-dev » 7.x-dev

the php module doesn't existing anymore in d8