SyntaxStudy
Sign Up
PHP Intermediate 3 min read

Classmap Autoloading

Classmap Autoloading

Classmap autoloading scans directories for class definitions and builds a static map — useful for legacy code without PSR-4 namespaces.

Example
"autoload": {
  "psr-4": { "App\\": "src/" },
  "classmap": ["lib/", "legacy/"],
  "files": ["src/helpers.php", "src/functions.php"]
}
# Optimised classmap (for production — faster than PSR-4 lookup)
composer dump-autoload --optimize
# Or combined with install
composer install --optimize-autoloader
Pro Tip

The files array is loaded on every request — keep it small and only for global helper functions.