Currently you can attempt to use variable_get() to check whether a persistent variable exists. This is problematic when the variable's value is NULL; the default value will be returned from variable_get(), so you can't distinguish between the two cases (1) the variable does not exist and (2) the variable exists but is NULL.

CommentFileSizeAuthor
#2 variable_exists-726906-1.patch835 bytessuperspring

Comments

Anonymous’s picture

It looks like this might be sorted as part of WSSCI: http://groups.drupal.org/node/179154.

superspring’s picture

Status: Active » Needs review
StatusFileSize
new835 bytes

I like the idea of adding a function which is consistant with the other variable_ functions.

This patch is very simple and just adds the function as specified.

cddoma’s picture

Issue summary: View changes

variable_exists() would be better than pulling the $conf array.
But in the mean time:

global $conf;
if (!isset($conf['your_variable'])) {
  variable_set('your_variable', 'variable_value');
}
anybody’s picture

The functionality makes sense, works good and the patch is OK.
+1 for RTBC, what about tests?

aubjr_drupal’s picture

Priority: Normal » Major

+1

Why didn't this ever get considered by the core maintainers? It has valid use cases.

avpaderno’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.