Skip to content

[docs] Coding style: document class constants and discourage global/namespaced constants #1666

Description

@safatshahin

What is the Moodle feature that needs documenting?

https://moodledev.io/general/development/policies/codingstyle#constants

The Constants section of the Moodle Coding Style currently only describes global constants, and both examples use define(). It says nothing about class constants, even though they are the preferred form in modern Moodle code and are explicitly covered by PSR-1 (and therefore by PSR-12 and PER-3.0, which we defer to where MCS is silent).

This leaves three gaps:

  • Developers have no documented guidance on class constant naming, and have to infer it from PSR-1.
  • The page implies define() is the normal way to declare a constant in new code.
  • Namespaced constants are not mentioned at all, despite being permitted by PHP and appearing in PSR examples. They don't support autoloading, and the PSR examples using PascalCase are a common source of confusion (see MDLSITE-7040).

Is this documentation specific to a Moodle version?

None

Are you able to provide a patch for this?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions