gitmyhub

instantiator

PHP ★ 11k updated 1d ago

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.

PHPComposersetup: easycomplexity 2/5

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.

Where it fits