A partial archive of https://discourse-mediawiki.wmflabs.org as of Saturday May 21, 2022.

How to define constants from extension code?

Osnard

I’d like to have the following in LocalSettings.php:

wfLoadExtension('MyExt');
$egMyExtMode = MYEXT_MODE_A;

Before extension schema this could be archived by using define() in the “setup file” (the one used in require_once). But now, even callback in extension.json is being evaluated after LocalSettings.php time and therefore using the constant within LocalSettings.php will fail as it is still undefined.

I did not find a nice example for something like this (e.g. FlaggedRevs defines constants but does not use extension.json)

Note: I do not want to define namespace constants, which can easily be done using extension.json/namespaces.

Tgr

Move away from constants, use strings. Since PHP-based configuration is going to being replaced with JSON/DB with well-defined caching semantics, eventually you’ll have to anyway.