Stop using uppercase TRUE, FALSE, NULL literals

Created on 10 April 2024, 8 months ago

Problem/Motivation

Drupal is one of the few (the only?) project that uses TRUE, FALSE and NULL uppercase in code in 2024.

Actually that is not even consistent: in PHPDoc when describing union types, the lowercase version is used.

We have plenty of code like (example)

  /**
   * Sort.
   *
   * @param int|null $flags
   *   The flags to sort.
   *
   * @return true
   *   Always return TRUE if no exceptions are thrown.
   *
   * @throws \Exception
   *   When...
   */
  public function sort(int|NULL $flags = NULL): TRUE {

This is confusing, but enforced via Coder, and non-Drupalers can get frustrated by this so in fact a barrier to contribution.

I propose to give in to the siege, lowercase these everywhere, and celebrate the invaders:

  /**
   * Sort.
   *
   * @param int|null $flags
   *   The flags to sort.
   *
   * @return true
   *   Always return TRUE if no exceptions are thrown.
   *
   * @throws \Exception
   *   When...
   */
  public function sort(int|null $flags = null): true {

Benefits

If we adopted this change, the Drupal Project would benefit by ...

Three supporters required

  1. https://www.drupal.org/u/ {userid} (date that user added support)
  2. https://www.drupal.org/u/ {userid} (date that user added support)
  3. https://www.drupal.org/u/ {userid} (date that user added support)

Proposed changes

Provide all proposed changes to the Drupal Coding standards . Give a link to each section that will be changed, and show the current text and proposed text as in the following layout:

1. {link to the documentation heading that is to change}

Add current text in blockquotes

Add proposed text in blockquotes

2. Repeat the above for each page or sub-page that needs to be changed.

Remaining tasks

  1. Add supporters
  2. Create a Change Record
  3. Review by the Coding Standards Committee
  4. Coding Standards Committee takes action as required
  5. Discussed by the Core Committer Committee, if it impacts Drupal Core
  6. Final review by Coding Standards Committee
  7. Documentation updates
    1. Edit all pages
    2. Publish change record
    3. Remove 'Needs documentation edits' tag
  8. If applicable, create follow-up issues for PHPCS rules/sniffs changes

For a full explanation of these steps see the Coding Standards project page

Feature request
Status

Active

Component

Coding Standards

Created by

🇮🇹Italy mondrake 🇮🇹

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

Comments & Activities

Production build 0.71.5 2024