The Coding Standards say this about naming global variables:

If you need to define global variables, their name should start with a single underscore followed by the module/theme name and another underscore.

However, Drupal core doesn't seem to follow this convention; I can't find a single example. Instead, it uses globals like $user, $theme, and $conf. Is the standard supposed to apply to core or just the contrib space?

Comments

traviscarden’s picture

Project: Documentation » Drupal core
Issue summary: View changes

Updated issue summary.

amrit_b’s picture

Project: Drupal core » Documentation
Status: Active » Closed (fixed)

Those instructions are only for contrib themes/modules.

traviscarden’s picture

Status: Closed (fixed) » Active

Thanks. We should probably make a note on the Coding Standards page then, do you think?

By the way, we aren't supposed to move issues directly into closed (fixed)—we move them to "fixed" instead so they don't fall off people's issue dashboard, and the Project issue tracking system will close them automatically after two weeks of inactivity.

Thanks!

amrit_b’s picture

Yeah definitely Travis, but I don't have permission to edit that page.. And sorry, I didn't know about the 'closed(fixed)' - thanks for the the info, will keep in mind now on wards.

jhodgdon’s picture

Project: Documentation » Drupal core
Version: » 8.x-dev
Component: Correction/Clarification » documentation
Issue tags: +Coding standards

Coding standards need to be discussed in the Drupal Core issue queue.

traviscarden’s picture

Status: Active » Needs review

I don't think this requires much discussion. It seems clear at this point that core is not meant to follow the same rule that contrib modules are for namespacing global variables. I would suggest just making that clear in the coding standards. Perhaps something like this:

If you need to define global variables, their name should start with a single underscore followed by the module/theme name and another underscore. (Drupal core is exempt from this standard.)

traviscarden’s picture

Issue summary: View changes

Updated issue summary.

pwarn’s picture

Issue summary: View changes

Since this has been sitting without comment for so long, should the issue be closed?

It doesn't seem clear that there is any change needed. "name should start" doesn't say that the "name is required to start". So the current documentation can be left as is, since it indicates best practice.

If the core folks decide that the coding standard should be changed, this should be talked about by the folks doing the core development, but is not clear that this is a documentation issue until someone decides to change something in the requirements for core.

jhodgdon’s picture

Status: Needs review » Closed (won't fix)

I don't even think we really have any global variables in Core in 8.x, so we probably do not need this issue at all.

Thanks for digging it up!