explaingit

doctrine/instantiator

11,005PHPAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

Tiny PHP library that creates class instances without running their constructors, useful when rebuilding objects from database rows or setting up test fixtures without triggering setup side effects.

Mindmap

mindmap
  root((Instantiator))
    What it does
      Skip constructors
      Blank object creation
      No side effects
    Use cases
      ORM hydration
      Unit testing
      Serialization
    Tech stack
      PHP
      Composer
    Audience
      PHP developers
      Framework builders
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Reconstruct a PHP object from a database row without triggering constructor arguments or validation logic.

USE CASE 2

Create a blank class instance in a unit test and set its properties directly, without mocking the constructor.

USE CASE 3

Build a custom ORM hydration layer that fills object properties from raw data after bypassing the constructor.

Tech stack

PHPComposer

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose including commercial projects, as long as you include the copyright and license notice.

In plain English

Doctrine Instantiator is a small PHP library that creates new instances of classes without calling their constructors. In PHP, when you create an object using the normal new keyword, the class's constructor function runs automatically. That constructor often expects arguments, performs setup work, or triggers side effects that are unnecessary or problematic when you just want a blank object to populate with data later. The library gives you a way to skip all of that initialization. You create one Instantiator object and call its instantiate method with the full name of any class, and it returns a bare instance of that class with none of the constructor logic having run. There is no configuration required and no other API surface to learn. This kind of tool comes up in larger PHP frameworks, particularly those that handle database persistence or testing infrastructure. When software needs to reconstruct an object from data stored in a database, it often wants to create the object first and then fill in its properties one by one, rather than supplying constructor arguments that may not make sense out of context. Testing tools also benefit from being able to create objects in a controlled initial state without triggering initialization side effects that would complicate the test. The library is maintained under the Doctrine organization, which produces a widely used set of PHP database and persistence tools. It was originally developed and maintained separately under a different name, then donated to Doctrine. Installation uses Composer, the standard PHP package manager. The README is brief because the library itself is narrow in scope.

Copy-paste prompts

Prompt 1
Show me how to use Doctrine Instantiator to create an instance of a class that requires constructor arguments, without calling the constructor.
Prompt 2
Write a PHP unit test that uses Instantiator to create a blank User object and then sets its name and email properties manually.
Prompt 3
How do I install doctrine/instantiator with Composer and call its instantiate method on a fully qualified class name?
Prompt 4
When should I use Doctrine Instantiator instead of the normal new keyword in PHP, and what are the trade-offs?
Open on GitHub → Explain another repo

← doctrine on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.