Article

Zend Framework 2 Modules: Boundaries and Load Order

How ZF2 modules merge configuration and services—and what to clean up before laminas-migration.

ZF2 modules are both code boundaries and configuration contributors. Broken migrations often start with modules that override each other’s service names or rely on undocumented load order.

// LEGACY Module.php fragment
namespace Invoice;
class Module
{
    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }
}
// MODERN post-migration — same shape, Laminas namespaces in dependencies
namespace Invoice;
class Module
{
    public function getConfig(): array
    {
        return include __DIR__ . '/config/module.config.php';
    }
}

Maintainer checklist

  • List modules in application.config.php and justify each
  • Find duplicate service keys across modules
  • Remove dead modules before running migrate to shrink diffs
  • Exclude generated module caches with -e during migrate

Hub: ZF2. Next: ServiceManager, migration.

Related tools

Related reading