Skip to content

Doctrine Instantiator

A PHP library that creates class instances without calling their constructors.doctrine/instantiator

Stars
11k
Forks
65
Licence
MIT
Language
PHP
Last update
19 days ago
Type
Library

What it is

Doctrine Instantiator is a PHP library that creates new objects from a class without running its constructor or using any of its own methods. It is a small utility, and the README describes it as the way Doctrine and similar tools avoid constructor logic when building objects. It is installed with Composer, PHP's standard package manager.

  • Create an instance of a PHP class with $instantiator->instantiate(ClassName::class) without calling its constructor
  • Build objects for tests when the constructor needs services or config that are hard to provide

Great for

  • PHP developers building ORMs, serializers, or other tools that need to create objects without running constructors
  • Maintainers of PHP libraries who need to rebuild objects from stored data
  • Developers writing tests that need an object of a class whose constructor has side effects or hard-to-satisfy dependencies

Not ideal for

  • Application developers who just need normal object creation, since skipping the constructor can leave objects with uninitialized properties
  • Non-PHP projects, because it only works with PHP classes
  • Teams that want a general-purpose framework rather than a single focused utility
Step-by-step guide: how to use Doctrine InstantiatorInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: PHP · Composer

    Install via Composer

    composer require doctrine/instantiator
  2. 2

    Run it

    • Install the package with Composer.
    • Create an instance of the Instantiator class.
    • Call instantiate() with the fully qualified class name you want to create.
  3. 3

    Get the most out of it

    • Read the project's CONTRIBUTING.md for guidance on contributing or reporting issues.
    • Check the Doctrine project homepage for documentation beyond the README.

Downloads

Strengths

  • Small, focused library with a single documented entry point
  • Installs with one Composer command
  • Maintained under the Doctrine project and migrated from the earlier ocramius/instantiator package

Trade-offs

  • Skipping the constructor can leave objects in an incomplete state, so callers must set values themselves
  • The README is brief and does not document edge cases or limitations in detail
  • Its use is niche and mainly aimed at library and framework authors

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.