In Drupal 6, the maximum length of variable names was increased from 48 to 128. This was required as many dynamic variable names ended up being longer than 48 characters. Is a length of 128 enough though? Why not just use a full varchar of 255?

CommentFileSizeAuthor
#4 25892.patch1.1 KBrobloach

Comments

webchick’s picture

some_long_module_name_dynamic_content_field_some_long_field_name

That's about the only case I can think of that would require super long variable names. And that's only 64 characters.

If someone *really* has a use case for a variable named something longer than some_long_module_name_dynamic_content_field_some_long_field_name_dont_even_know_what_to_possibly_put_here_to_make_it_long_enough, then they should rewrite their logic because obviously something is wrong. :P

Won't fix, imo.

chx’s picture

Status: Active » Closed (won't fix)
deekayen’s picture

This is a live example:

node_privacy_byrole_default_grant_perms_content_type_content_canadian_signage_request

Namespace: node_privacy_byrole
Permission name: default_grant_perms
Content name (32 char limit): content_type_content_canadian_signage_request

In all, that's 86 characters, albeit well within the 128, but it's an example of how variable names can get long easily.

The system table allows 255 characters for storing the module config. If you remove sites/all/modules/ and .module, that leaves Drupal core support for the average site to allow for 229 characters as the module name as the allowable namespace minus the directory name of the module. Divide 229 by 2 (module directory and .module name) and the max allowed module name size (that would consume a variable namespace) would be 114 characters (give or take depending on where it's installed).

At 114 characters, appending one CCK content type to the variable name runs right past the 128 limit.

I use a real module named field_privacy_by_role_and_workflow_state. It might be nice at some point to have a variable name to set default values on a field:

field_privacy_by_role_and_workflow_state_content_type_content_canadian_signage_request_field_accounts_payable_email_address_visible

namespace: field_privacy_by_role_and_workflow_state
content type: content_type_content_canadian_signage_request
field: field_accounts_payable_email_address
permission name: visible
Total characters: 132

Obviously this isn't something I would be typing - it would be programmatically accessed, but that is a real module and real CCK stuff. As it is now, I would have to do some alternative like put part of it in an array. Let me remind you that the variable values are stored serialized, so to query that serialized data later outside the scope of variable_get() for a different purpose would make my eyes bleed and probably scare my coworkers.

So I ask if the field is varchar anyway, what's so special about 128? Why not 100 or 150? At least 255 is a limiter based on database design.

robloach’s picture

StatusFileSize
new1.1 KB

Well, here's an untested patch.

jimkont’s picture

Hi,

An example that variables needs to be bigger is the realname module where you store tokens to form the desired user name format.

since tokens strings are now (D7) bigger in size and we use more expressive user profile filed names the variable size is not enough...

cheers,
Dimitris

dimitris.spachos’s picture

Subscribing!