4

I'm using Drupal 6, and I'm having problems retrieving a set of variables I set with variable_set() using variable_get(). I'm doing a dpr(get_defined_vars()) to see what's defined, and I don't see my variables; I see only the arrays $form and $form_state (this is inside hook_submit()).

Does get_defined_vars() show all the variables defined via variable_get()/variable_set()? I would just like to see a list of all of them. I just need to see if they've been set correctly, and troubleshoot why I can't retrieve them.

6

get_defined_vars is a PHP function, not a Drupal function. It basically shows you all variables that are in scope.

Drupal variables set by variable_set are not automatically within scope.

Variables are stored in global $conf; but I don't recall if non-variables are also stored here.

If you install the Devel Module there is a page for viewing and editing variables.

EDIT:

Curiosity got to me. The variable editor in the Devel Module queries the {variable} table and not global $conf; to build the form of all available variables, so that suggests that is the proper way to do it.

1

What you set with variable_set() are called "Drupal variables," or "persistent variables." They are not PHP variables, and get_defined_vars() doesn't return them.

During bootstrap, the content of the "variables" table is copied into the global variable $conf that contains also values set in settings.php, such as the string overrides.

$conf['locale_custom_strings_en'] = array(
  'forum'      => 'Discussion board',
  '@count min' => '@count minutes',
);

If you want to verify which Drupal variables are set, then you can use the global variable $conf, but I would suggest to do it only for debugging purposes, and not in code that you publicly distribute or use outside a test site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.