Ensure all modules are autoloaded with PSR-4 only if enabled

Created on 20 July 2015, almost 10 years ago
Updated 11 May 2025, 3 days ago

Problem/Motivation

1. D7 => D8 WTF - Using e.g. sites/all/modules/memcache/memcache.inc did just work, but the same with classes does not - until the module is enabled, which can be very problematic to deploy production changes. (How do you sync the settings.php change with the enabling of the module without the site WSOD'ing in between?)

2. In a composer enabled world the expectation is that modules have a composer.json, which specifies the folders to autoload, which is then automatically loaded. Once a module starts using autoload: psr-4: { 'Drupal\\my_module\\': 'src/'} we get a huge behavior change for a disabled vs. an enabled module when that module is managed by composer or not.

3. Small DX problems, e.g. to override the container class with one from a module, explicitly the autoloader has to be used to addPsr4() for the module.

Proposed resolution

- Always load PSR-4 for all available modules.

This is a step in transitioning us to a static composer world - as the rest of the PHP world already uses.

Remaining tasks

- Discuss
- Create patch

User interface changes

- None

API changes

- Behavior change: Modules src/ directory classes are always available in the autoloader.
- Composer managed modules can add autoload: psr-4 safely as there is no change in behavior.

Data model changes

- None

📌 Task
Status

Active

Version

11.0 🔥

Component

base system

Created by

🇩🇪Germany Fabianx

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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