2

Are there any restrictions, conventions, etc. for the names of persistent variables created with variable_set()?

Aside from project name prefix, I haven't found anything in the documentation. However, I notice that most modules restrict themselves to the same rules that apply to PHP variables.

1 Answer 1

1

Until Drupal 7, the main storage for the variables is the variable table in the same database Drupal uses.

The name column is a varchar(128) so that requires the variable names to have equal or fewer characters than 128.

Prefixing the variable names is purely by convention. Drupal Form API can handle spaces in machine names too, but you will almost never see a form array item key with spaces in it.

There are workarounds, but it's easier if there are no spaces, for example when you use drush, export settings, etc.

2
  • What characters does the Drupal Form API have trouble with?
    – donut
    Commented Nov 13, 2015 at 21:53
  • None. You can even use a hash itself, which is used to differentiate form properties from child elements. But it's much harder to scan by eyes and must put extra effort to wrap the strings with quotes or something when using.
    – AKS
    Commented Nov 13, 2015 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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