Decide on a coding style for PHP Enumerations

Created on 6 February 2023, about 2 years ago

Problem/Motivation

Enumerations were added to PHP in 8.1.
Whilst they can't be added to Drupal 9 core which still still supports down to PHP 7.3, custom/contrib code being developed on branches that support PHP >= 8.1 or Drupal >=10.0 may wish to take advantage of this language feature.

It is not currently mentioned in the Drupal Coding Standards, but it would be good to add consistency through standardisation, for example to enforce a common casing for the names of enums and the values within them.

Should we follow the rule for class naming to use Pascal case? Should the values therein be in uppercase with words separated by underscores, as we do for constants?

Or does something else make sense?

Raising now because today I've seen three different variations of casing around enums in custom code.

Steps to reproduce

N/A

Proposed resolution

To be discussed

Remaining tasks

Discuss what the proposed resolution might be.
Update documentation.
Update sniffs.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Feature request
Status

Active

Component

Coding Standards

Created by

🇬🇧United Kingdom Eli-T Manchester

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

Comments & Activities

Production build 0.71.5 2024