Consistent styling for the NULL/TRUE/FALSE symbols

Created on 19 January 2022, about 3 years ago
Updated 7 May 2023, almost 2 years ago

Problem/Motivation

The styling of "NULL"/"TRUE"/"FALSE" and "null"/"true"/"false" is inconsistent:

  • For PHP code, "NULL"/"TRUE"/"FALSE" are expected to be uppercase.
  • For PHP docblocks, "null"/"true"/"false" are expected to be lowercase.

This leads to silly things. For example... If I copy a symbol from a valid docblock (eg "false") and paste it into code, then the linter rejects the symbol (preferring "FALSE"). The same problem happens in reverse (copying symbols from code to a docblock).

What's the point of docblocks if they can't document the actual symbols expected in the code?

Steps to reproduce

The following code is internally consistent - but it's rejected because of "Drupal.Commenting.FunctionComment.IncorrectParamVarName":

/**
 * Snafu.
 *
 * @param string|NULL $a
 *   Some kind of parameter.
 */
function snafu($a) {
  if ($a === NULL) {
    echo 'Your style guide is consistent.';
  }
}

The following code is internally consistent - but it's rejected because of "Generic.PHP.UpperCaseConstant.Found":

/**
 * Snafu.
 *
 * @param string|null $a
 *   Some kind of parameter.
 */
function snafu($a) {
  if ($a === null) {
    echo 'Your style guide is consistent.';
  }
}

The following code is accepted by the linter as valid style - but it is internally inconsistent. Symbols in code and documentation cannot match.

/**
 * Snafu.
 *
 * @param string|null $a
 *   Some kind of parameter.
 */
function snafu($a) {
  if ($a === NULL) {
    echo 'Your style guide is inconsistent.';
  }
}

Proposed resolution

Either:

  1. Accept uppercase "NULL"/"TRUE"/"FALSE" in docblocks. The Coding standards specify that NULL/TRUE/FALSE are uppercase. They include no exceptions for docblocks. This would be consistent with Drupal standards.
  2. Pursue a change in the Coding standards . The PHP language/community have evolved in the time since the standard was written (wrt type expressions in method-signatures, class properties, union-types). php.net docs frequently uses lower-case "null", "false", etc (example doc). This would be consistent with PHP upstream - but requires more formal change-management on the drupal.org side .

Remaining tasks

Either:

  1. Prefer "NULL"/"TRUE"/"FALSE". Invert "Drupal.Commenting.FunctionComment.IncorrectParamVarName" (or disable it for a transitional period).
  2. Prefer "null"/"true"/"false". Invert "Generic.PHP.UpperCaseConstant.Found" (or disable it for a transitional period).

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Feature request
Status

Active

Component

Coding Standards

Created by

🇺🇸United States totten

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024