doctrine/common
Doctrine Common extends core PHP with shared utilities used across Doctrine projects. Includes collections, event management, caching helpers, annotations support (legacy), reflection and class loading tools. A foundational component for Doctrine ORM and related libraries.
Start by requiring the package via Composer:
composer require doctrine/common
Despite its age (last release 2025-01-01 suggests future-dated), doctrine/common is largely stable and backward-compatible — many of its components are now decoupled or rehomed in newer packages (e.g., doctrine/persistence, doctrine/deprecations).
First use case: if you’re building a Doctrine-based application (e.g., ORM or DBAL), you likely already depend on it transitively, but explicitly requiring it allows you to use its foundational utilities (e.g., Doctrine\Common\Collections\Collection) directly.
Doctrine\Common\Collections\Collection and Expr for in-memory filtering:
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Expr\Expr;
$users = new Collection($userArray);
$activeAdmins = $users->matching(
Expr::andX(
Expr::eq('isActive', true),
Expr::eq('role', 'admin')
)
);
Doctrine\Common\EventManager) to hook into custom lifecycle events:
$em = new EventManager();
$em->addEventListener('user.created', new UserWelcomeListener());
Doctrine\Common\Annotations\Reader for custom annotation-driven configuration in your own libraries (e.g., command decorators, config attributes).Proxy\ProxyFactory only when implementing custom object hydration or lazy-loading strategies.Annotations → doctrine/annotationsCache → doctrine/cache (deprecated; use PSR-6/PSR-16 instead)Persistence → doctrine/persistenceDoctrine\Common for cache/annotations may cause class-not-found errors.Doctrine\Common\Collections\ArrayCollection over plain arrays for better IDE inference and typehinting (Collection interface).Doctrine\Common\EventSubscriber — ensure your subscribers implement getSubscribedEvents() and use consistent naming (e.g., onUserPersist, not onUserPersist()).doctrine/persistence is also present for compatibility.doctrine/deprecations via handle() to catch subtle breaking changes in underlying Doctrine APIs.How can I help you explore Laravel packages today?